Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

First, create and copy the below data (not the captions) into a file name Refere

ID: 3703450 • Letter: F

Question

First, create and copy the below data (not the captions) into a file name Referees.dat

ID            FName LName                  Grade                  

0001       Mike      Apple                    CLUB                    

0012       Josh       Boeing                  STATE                   
0103       Linda     Intel                       STATE                   
0084       John      Rambus                  NATIONAL         
0205       Becky    Sirius                     CLUB                    
0045       Tom       Skyworks             CLUB                    
0807       Kevin     Suzuki                   NATIONAL         
0074       Henry    Xilinx                     STATE                   

You are to write a program to do the followings:

Define an enumeration type RefereeGrade including 5 values UNKNOWN, CLUB, STATE, NATIONAL and FIFA.

Define a structure named SReferee containing data members for the following information:

·         Id (typed string)

·         First Name (typed string)

·         Last Name (typed string)

·         Grade (typed RefereeGrade)

Then, create an array of 30 elements typed SReferee to read the data from the file Referees.dat into this array.

Create a menu with the following options:

1.List all referees

2.List all referees of a specific grade

3.List all referees with grade less than a specific grade

4.List all referees with grade more than a specific grade

5.List information of a specific referee using the Id

6.List information of a specific referee using the names

7.Add a referee

8.Remove a referee using Id

9.Update referee grade using Id

10.Quit

For option Quit, before quitting your program, you have to write all referee information back to the file Referees.dat to keep the updated information of referees.

The coding language is c++

I have the layout already setup/partially given. Any help would be greatly appreciated!

#include <iostream>

#include <string>

using namespace std;

struct SReferee

{

// Your definition here

};

int menu ();

void listAllReferees ();

void listRefereesOfSpecificGrade ();

void listtRefereesWithGradeLessThanSpecificGrade ();

void listtRefereesWithGradeMoreThanSpecificGrade ();

void listtRefereeInfoWithId ();

void listtRefereeInfoWithNames ();

void addNewReferee ();

void removeReferee ();

void updateRefereeGrade ();

void Quit();

SReferee referees[30];

// Function to read referee information from the file Referees.dat

void readRefereeInfo();

// Function to write referee information back to the file Referees.dat

void writeRefereeInfo();

void main()

{

// Read referee information from the file Referees.dat

readRefereeInfo();

       int choice;

       do {

              system("CLS");

              choice = menu();

              switch (choice) {

              case 1:

                    listAllReferees ();

                     break;

              case 2:

                    listRefereesOfSpecificGrade ();

                     break;

              case 3:

                    listtRefereesWithGradeLessThanSpecificGrade ();

                     break;

              case 4:

                    listtRefereesWithGradeMoreThanSpecificGrade ();

                     break;

              case 5:

                    listtRefereeInfoWithId ();

                     break;

              case 6:

                    listtRefereeInfoWithNames ();

                     break;

              case 7:

                    addNewReferee ();

                     break;

              case 8:

                    removeReferee ();

                     break;

              case 9:

                    updateRefereeGrade ();

                     break;

              case 10:

                     Quit();

                     break;

              default:

                     cout<< "That was an invalid choice, please try again! ";

              }

              system("PAUSE");

       } while (choice > 0 && choice < 10);

system("PAUSE");

}

int menu ()

{

       int option;

       cout<< "             REFEREE ASSIGNING SYSTEM ";

       cout<< " 1. List All Referees. ";

       cout<< " 2. List All Referees Of A Specific Grade. ";

       cout<< " 3. List All Referees With Less Than A Specific Grade. ";

       cout<< " 4. List All Referees With More Than A Specific Grade. ";

       cout<< " 5. List Referee Information With ID. ";

       cout<< " 6. List Referee Information With Names. ";

       cout<< " 7. Add New Referee. ";

       cout<< " 8. Remove A Referee. ";

       cout<< " 9. Update Referee Grade. ";

       cout<< "10. Quit. ";

       cout<< "Please select your option: ";

       cin>> option;

       while (option < 1 || option > 10)

       {

              cout<< "Invalid option!!! Please select valid option: ";

              cin>> option;

       }

       return option;

}

void listAllReferees ()

{

       cout<< "Inside listAllReferees () "; //Remove when starting coding

       //Your code here

}

void listRefereesOfSpecificGrade ()

{

       cout<< "Inside listRefereesOfSpecificGrade () "; //Remove when starting coding

       //Your code here

}

void listtRefereesWithGradeLessThanSpecificGrade ()

{

       cout<< "Inside listtRefereesWithGradeLessThanSpecificGrade () "; //Remove when starting coding

       //Your code here

}

void listtRefereesWithGradeMoreThanSpecificGrade ()

{

       cout<< "Inside listtRefereesWithGradeMoreThanSpecificGrade () "; //Remove when starting coding

       //Your code here

}

void listtRefereeInfoWithId ()

{

       cout<< "Inside listtRefereeInfoWithId () "; //Remove when starting coding

       //Your code here

}

void listtRefereeInfoWithNames ()

{

       cout<< "Inside listtRefereeInfoWithNames () "; //Remove when starting coding

       //Your code here

}

void addNewReferee ()

{

       cout<< "Inside addNewReferee () "; //Remove when starting coding

       //Your code here

}

void removeReferee ()

{

       cout<< "Inside removeReferee () "; //Remove when starting coding

       //Your code here

}

void updateRefereeGrade ()

{

       cout<< "Inside updateRefereeGrade () "; //Remove when starting coding

       //Your code here

}

void Quit()

{

// Write Referee information back to the file Referees.dat

writeRefereeInfo();

       cout<< "Have a nice day ";

}

Explanation / Answer

Here is the complete program in C++ and i have included one extra search method also .
You have to change the file path only. If you like this answer please give your feedback.Thakns.
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
typedef struct SReferee {
string Id ;
string First_Name;
string Last_Name;
string Grade;
} S;
enum RefereeGrade {UNKNOWN, CLUB, STATE, NATIONAL,FIFA};
const int SIZE = 30;
void showChoices();
void ListReferees();
void ListRefereesG(string grade);
RefereeGrade convert(const std::string& str);
void ListRefereesLTG(string grade);
void ListRefereesMTG(string grade);
void ListRefereesID(string id);
void ListRefereesName(string FirstName,string LastName);
SReferee setData();
void add_record();
void search(string id);
void delete_record(string id);
void modify_record(string id);
ofstream outFile;
ifstream inFile;
fstream file;
int convertToInt(string id){
// object from the class stringstream
stringstream geek(id);
// The object has the value 12345 and stream
// it to the integer x
int x = 0;
geek >> x;
return x;
}
string convertToString(int num){
// declaring output string stream
ostringstream str1;
// Sending a number as a stream into output
// string
str1 << num;
// the str() coverts number into string
string gk = str1.str();
return gk;
}
SReferee* readFile(){
ifstream in_stream;
ofstream out_stream;
int array_size = 31;
static SReferee arr[SIZE+1];

int position = 1;
//double numbers[array_size];
//Check input and output file.
in_stream.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat"); //Full path of the file
//in_stream.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/A.dat");
if (in_stream.fail())
{
cout << "Input file opening failed";
exit(1);
}
//array to read data from array as long as we dont reach the end of file marker
while (position < array_size && in_stream >> arr[position].Id && in_stream >> arr[position].First_Name
&& in_stream >> arr[position].Last_Name && in_stream >> arr[position].Grade)
{
/* cout << position << " = "
<< arr[position].Id << " "
<< arr[position].First_Name<< " "
<< arr[position].Last_Name << " "
<< arr[position].Grade<< " "<< endl;*/
position++;
}
in_stream.close();
out_stream.close();
//cout<<"LEN "<<position<<endl;
arr[0].Id=convertToString(position-1);
return arr;
}
int main()
{
int choice;
string grade;
string id;
string FirstName,LastName;
do
{
showChoices();
cin >> choice;
switch (choice)
{
case 1:
ListReferees();
break;
case 2:
cout << "Enter Grade ";
cin>>grade;
ListRefereesG(grade);
break;
case 3:
cout << "Enter Grade ";
cin>>grade;
ListRefereesLTG(grade);
break;
case 4:
cout << "Enter Grade ";
cin>>grade;
ListRefereesMTG(grade);
break;
case 5:
cout << "Enter id ";
cin>>id;
ListRefereesID(id);
break;
case 6:
cout << "Enter full name (space separated firstName and LastName)";
cin>>FirstName;
cin>>LastName;
ListRefereesName(FirstName,LastName);
break;
case 7:
add_record();
break;
case 8:
cout << "Enter id ";
cin>>id;
delete_record(id);
break;
case 9:
cout << "Enter id ";
cin>>id;
modify_record(id);
break;
case 10:
break;
default:
cout << "Invalid input" << endl;
}
}while (choice != 10);
return 0;
}
void showChoices()
{
cout << "MENU" << endl;
cout << "1. List all referees" << endl;
cout << "2. List all referees of a specific grade" << endl;
cout << "3. List all referees with grade less than a specific grade " << endl;
cout << "4. List all referees with grade more than a specific grade " << endl;
cout << "5. List information of a specific referee using the Id" << endl;
cout << "6. List information of a specific referee using the names" << endl;
cout << "7. Add a referee" << endl;
cout << "8. Remove a referee using Id" << endl;
cout << "9. Update referee grade using Id" << endl;
cout << "10. Quit" << endl;
cout << "Enter your choice :";
}
void ListReferees(){
SReferee *arr=readFile();
int n=convertToInt(arr[0].Id) ;
//cout<<" n val "<<n<<endl;
//int n=sizeof(arr[0]);
int i=0;
cout << " All Referees " << endl;
for(i=1;i<=n;i++){
cout << arr[i].Id << " "
<< arr[i].First_Name<< " "
<< arr[i].Last_Name << " "
<< arr[i].Grade<< " "<< endl;
}
}
void ListRefereesG(string grade){
SReferee *arr=readFile();
int n=convertToInt(arr[0].Id) ;
int i=0;
cout << " All Referees of grade "<< grade<< endl;
for(i=1;i<=n;i++){
if(arr[i].Grade==grade){

cout << arr[i].Id << " "
<< arr[i].First_Name<< " "
<< arr[i].Last_Name << " "
<< arr[i].Grade<< " "<< endl;
}
}
}
RefereeGrade convert(const std::string& str)
{
if(str == "CLUB") return CLUB;
else if(str == "STATE") return STATE;
else if(str == "NATIONAL") return NATIONAL;
else if(str == "FIFA") return FIFA;
else return UNKNOWN;
}
void ListRefereesLTG(string grade){//less than grade
SReferee *arr=readFile();
int n=convertToInt(arr[0].Id) ;
int i=0;
cout << " All Referees less than of grade "<< grade<< endl;
for(i=1;i<=n;i++){
if(convert(arr[i].Grade)<convert(grade)){

cout << arr[i].Id << " "
<< arr[i].First_Name<< " "
<< arr[i].Last_Name << " "
<< arr[i].Grade<< " "<< endl;
}
}
}
void ListRefereesMTG(string grade){//more than grade
SReferee *arr=readFile();
int n=convertToInt(arr[0].Id) ;
int i=0;
cout << " All Referees more than of grade "<< grade<< endl;
for(i=1;i<=n;i++){
if(convert(arr[i].Grade)>convert(grade)){

cout << arr[i].Id << " "
<< arr[i].First_Name<< " "
<< arr[i].Last_Name << " "
<< arr[i].Grade<< " "<< endl;
}
}
}
void ListRefereesID(string id){// list by id
SReferee *arr=readFile();
int n=convertToInt(arr[0].Id) ;
int i=0;
cout << " Referee of id "<< id<< endl;
for(i=1;i<=n;i++){
if(arr[i].Id==id){

cout << arr[i].Id << " "
<< arr[i].First_Name<< " "
<< arr[i].Last_Name << " "
<< arr[i].Grade<< " "<< endl;
break;
}
}
}
void ListRefereesName(string FirstName,string LastName){
SReferee *arr=readFile();
int n=convertToInt(arr[0].Id) ;
int i=0;
cout << " Referee of name "<< FirstName<<" "<<LastName << endl;
for(i=1;i<=n;i++){
if(arr[i].First_Name==FirstName && arr[i].Last_Name==LastName){

cout << arr[i].Id << " "
<< arr[i].First_Name<< " "
<< arr[i].Last_Name << " "
<< arr[i].Grade<< " "<< endl;
break;
}
}
}
SReferee setData(){
//cout<<"setData called"<<endl;
SReferee obj;
string Id ;
string First_Name;
string Last_Name;
string Grade;
cout<<" Enter id of the Record to be added: ";
cin>>Id;
cout<<" Enter FirstName of the Record to be added: ";
cin>>First_Name;
cout<<" Enter LastName of the Record to be added: ";
cin>>Last_Name;
cout<<" Enter Grade of the Record to be added: ";
cin>>Grade;
obj.Id=Id;
obj.First_Name=First_Name;
obj.Last_Name=Last_Name;
obj.Grade=Grade;
return obj;
}
void add_record()
{
//cout<<"add_record called"<<endl;
outFile.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat", ios::binary | ios::app);
SReferee obj=setData();
outFile<<" ";
outFile <<obj.Id << " "
<< obj.First_Name<< " "
<< obj.Last_Name << " "
<< obj.Grade;
// outFile.write(reinterpret_cast<char *>(&obj), sizeof(SReferee));
cout<<"record added successfully having ID = "<<obj.Id<<endl;
outFile.close();
}
/*
* function to search and display from binary file
*/
void search(string id)
{

SReferee obj;
int array_size = 30;

int position = 0;
//double numbers[array_size];
//Check input and output file.
inFile.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat"); //Full path of the file
//in_stream.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/A.dat");
if (inFile.fail())
{
cout << "Input file opening failed";
exit(1);
}
//array to read data from array as long as we dont reach the end of file marker
while (position < array_size && inFile >> obj.Id && inFile >> obj.First_Name
&& inFile >> obj.Last_Name && inFile >> obj.Grade)
{
if(obj.Id==id){
cout<<" Found at line no: "<<position<<endl;
cout <<obj.Id << " "
<< obj.First_Name<< " "
<< obj.Last_Name << " "
<< obj.Grade<<" ";
break;
}
position++;
}

inFile.close();
}
/*
* function to delete a record
*/
void delete_record(string id)
{
SReferee obj;
int array_size = 30;

int position = 0;
//double numbers[array_size];
//Check input and output file.
inFile.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat"); //Full path of the file
//in_stream.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/A.dat");
if (inFile.fail())
{
cout << "Input file opening failed";
exit(1);
}
outFile.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/temp.dat", ios::out | ios::binary);
//array to read data from array as long as we dont reach the end of file marker
while (position < array_size && inFile >> obj.Id && inFile >> obj.First_Name
&& inFile >> obj.Last_Name && inFile >> obj.Grade)
{
if(obj.Id!=id){
outFile <<obj.Id << " "
<< obj.First_Name<< " "
<< obj.Last_Name << " "
<< obj.Grade<<" ";
}
position++;
}
inFile.close();
outFile.close();

remove("C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat");
rename("C:/Users/SAHANUR/Documents/CheggProgramsCpp/temp.dat", "C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat");
}
SReferee setNewData(string id){
//cout<<"setNewData called"<<endl;
SReferee obj;
string Id;
string First_Name;
string Last_Name;
string Grade;
char ch;
cout<<"do you want to change the id (Y/N): ";
cin>>ch;
if(ch=='Y'){
cout<<" Enter new ID of the Record to be modified: ";
cin>>Id;
}
cout<<" Enter FirstName of the Record to be modified: ";
cin>>First_Name;
cout<<" Enter LastName of the Record to be modified: ";
cin>>Last_Name;
cout<<" Enter Grade of the Record to be modified: ";
cin>>Grade;
if(ch=='Y'){
obj.Id=Id;
}else{
obj.Id=id;
}

obj.First_Name=First_Name;
obj.Last_Name=Last_Name;
obj.Grade=Grade;
return obj;
}
/*
* function to modify a record
*/
void modify_record(string id)
{

SReferee obj,newObj;
int array_size = 30;

int position = 0;
//double numbers[array_size];
//Check input and output file.
inFile.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat"); //Full path of the file
//in_stream.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/A.dat");
if (inFile.fail())
{
cout << "Input file opening failed";
exit(1);
}
outFile.open("C:/Users/SAHANUR/Documents/CheggProgramsCpp/temp.dat", ios::out | ios::binary);
//array to read data from array as long as we dont reach the end of file marker
while (position < array_size && inFile >> obj.Id && inFile >> obj.First_Name
&& inFile >> obj.Last_Name && inFile >> obj.Grade)
{
if(obj.Id!=id){
outFile <<obj.Id << " "
<< obj.First_Name<< " "
<< obj.Last_Name << " "
<< obj.Grade<<" ";
}else{
newObj=setNewData(id);
outFile <<newObj.Id << " "
<< newObj.First_Name<< " "
<< newObj.Last_Name << " "
<< newObj.Grade<<" ";
}
position++;
}
inFile.close();
outFile.close();

remove("C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat");
rename("C:/Users/SAHANUR/Documents/CheggProgramsCpp/temp.dat", "C:/Users/SAHANUR/Documents/CheggProgramsCpp/Referees.dat");
}