C Programing Binary File IO Football Game Scores Write a pro
C++ Programing Binary File I/O
Football Game Scores
Write a program that stores the following data about football game in a structure:
Field Name
Description
visit_team
c-string (name of visiting team)
home_score
Int
visit_score
Int
This program will NOT need an array of structures. Instead, store the data in a file named “football.dat”. Your program will use a structure to read/write a record as needed.
Your program should have a menu that allows the user to perform the tasks shown below.
Add a game
Print the information for all games, in table form.
Print the information for a specific game, given the name, or part of the name.
Edit a game.
Your program should allow the user to make selections until they choose a 5th option “Exit Program” which will end the program.
Your program should be modular. Use a separate function for each option stated above. Your output should be well-organized, neat, and easy to read.
| Field Name | Description | 
| visit_team | c-string (name of visiting team) | 
| home_score | Int | 
| visit_score | Int | 
Solution
#include <iostream>
 #include <fstream>
 using namespace std;
struct FootBallGame
 {
 char visit_team[100];
 int home_score;
 int visit_score;
 }gameData[100];
int addGame(int n)
 {
    cout<<endl<<\"Enter visit team: \";
    cin>>gameData[n].visit_team;
    cout<<endl<<\"Enter home score: \";
    cin>>gameData[n].home_score;
    cout<<endl<<\"Enter visit score: \";
    cin>>gameData[n].visit_score;
    cout<<endl<<\"New Game added\";
    return n;
 }
void displayAll(int n)
 { cout<<endl<<\"Game details: \";
 cout<<endl<<\"Visit Team \\t home score \\t visit score\";
    for(int i=0;i<n;i++)
    {
        cout<<endl<<gameData[i].visit_team<<\" \\t \"<<gameData[i].home_score<<\"\\t\"<<gameData[i].visit_score;
     }
 }
void displayGame(char name[100],int n)
 {
    int flag=0;
 for(int i=0;i<n;i++)  
 {
     if(gameData[i].visit_team.compare(name)==0)
     {
         cout<<endl<<\"Visit team: \"<<gameData[i].visit_team;
        cout<<endl<<\"Home Score: \"<<gameData[i].home_score;
        cout<<endl<<\"Visit score: \"<<gameData[i].visit_score;
        flag=1;
        break;
    }
 }
 if(flag==0)
 {
     cout<<endl<<\"Game not found\";
 }
 }
void editGame(char name[100],int n)
 {
 int flag=0;
 for(int i=0;i<n;i++)  
 {
     if(gameData[i].visit_team.compare(name)==0)
     {
     cout<<endl<<\"Enter new visit team: \";
    cin>>gameDatain].visit_team;
    cout<<endl<<\"Enter new home score: \";
    cin>>gameData[i].home_score;
    cout<<endl<<\"Enter new visit score: \";
    cin>>gameData[i].visit_score;
    cout<<endl<<\"Game edited\";
        flag=1;
        break;
    }
 }
 if(flag==0)
 {
     cout<<endl<<\"Game not found\";
 }
 }
int main()
 {
    ifstream infile(\"football.dat\");
    int n=0;
    while(!infile.eof())
    {
        infile>>gameData[n].visit_team>>gameData[n].home_score>>gameData[n].visit_score;
         n++;
    }
   
    while(1)
    {
        cout<<endl<<\"1.Add a game\";
        cout<<endl<<\"2.Print the information for all games, in table form.\";
        cout<<endl<<\"3.Print the information for a specific game, given the name.\";
        cout<<endl<<\"4.Edit a game.\";
        cout<<endl<<\"5.exit\";
        cout<<endl<<\"Enter your choice: \";
        int choice;
        cin>>choice;
        switch(choice)
        {
            case 1: n=addGame(n); break;
            case 2: displayAll(n);break;
            case 3: char name[100];
            cout<<endl<<\"Enter name: \";
            cin>>name;
                    displayGame(name,n); break;
            case 4: char name[100];
            cout<<endl<<\"Enter name: \";
            cin>>name;
                    editGame(name,n);break;
            case 5:
                exit(0);
        }
    }
 }



