// Stephen van Someren Greve// CSCI 140// 4/11/08//// This is a program description. It does what it is programmed to do.#include <iostream>#include <fstream>#include <iomanip>using namespace std;// Player is a data type (a structure) that is an aggregate of all of the// significant aspects of a baseball player. For the purposes of this program,// there is very little data to manage: A name, times at bat, an number of// hits. struct Player { string _name; // Player's name (e.g., Bob) unsigned int _at_bat; // Times up at bat float _num_hits;// Number of successful hits};const int NOTFOUND = -1; // Sentenal for FindPlayeristream& operator>>(istream& stream, Player& player);ostream& operator<<(ostream& stream, const Player& player);int FindPlayer( Player team[], int player_ct, string Name);// main// This is the main body of the program. // TODO: Document me.int main(){ // The team of players. Player team[93]; unsigned int team_size = 0; int menu; string Name, hit, match; int player_ct = 0; // This could be a separate function (e.g., read_team). ifstream fin("player.data"); Player p; fin >> p; while( fin.good() ) { team[team_size] = p; ++team_size; fin >> p; } cout << "MENU\n" << "1) Report a player's batting average\n" << "2) Report all players' batting averages\n" << "3) Update a player's batting average\n" << "4) Save and quit\n" << "Choice:"; cin >> menu; if (menu == 1){ cout << "Which player?"; Player name; cin >> name; cout << name._num_hits/name._at_bat; } if (menu == 2){ ifstream fin("player.data"); cout << "Player" << setw(15) << "Avg" << endl << "---------" << setw(15) << "----" << endl; while ( fin.good() ) { //team[player_ct]._name; cout << team[player_ct]._name << setw(15) << team[player_ct]._num_hits / team[player_ct]._at_bat << endl; ++player_ct; } } if (menu == 3){ cout << "Which player? "; Player name; cin >> name; cout << "Did " << name._name << " get a hit? "; cin >> hit; if(hit == "yes"){ ++name._num_hits; ++name._at_bat; } if(hit == "no"){ ++name._at_bat; } else cout << "Please enter only yes or no.\n"; } return 0;}// operator <<// stream The output stream which will receive player's data.// player The player to write in to stream.// return The reference stream (for chaining inserts).//// This function will write the significant data contained in player to the// stream.ostream& operator<<(ostream& stream, const Player& player){ stream << player._name << player._at_bat << player._num_hits; return stream;}// operator >>// stream The output stream which will receive player's data.// player The player to write in to stream.// return The reference stream (for chaining inserts).//// This function will read the significant data contained in player to the// stream.istream& operator>>(istream& stream, Player& player){ stream >> player._name >> player._at_bat >> player._num_hits; return stream;}// FindPlayer// team All of the player.// player_ct The number of players in the team.// Name The name of the player to find.// This is how I'm going to find the player named Name.int FindPlayer( Player team[], int player_ct, string Name){ ifstream fin("player.data"); Player p; fin >> p; while( fin.good()){ if( p._name == Name);{ cout << "Found Name!"; } ++player_ct; return 0; } return NOTFOUND;}