/** * @file assignment10.cpp * @description This application creates a TeamStats objects and allows * the user to add Team information (Name, wins, and losses) * then outputs the information the user provided. * @course CSCI 123 Section 00000 * @assignment 10 * @date 10/20/2008 * @author Brad Rippe (00000000) brippe@fullcoll.edu * @version 1.0 */ #include #include #include // setfill, setw using namespace std; /* I usually provide my global constants before anything else */ const int TEAMS = 2; const int WIDTH = 15; /** * Team Stats encapsulates a team name, number of wins, * and number of losses. * (NOTE: ALL user defined types require documentation) */ struct TeamStats { string mTeamName; int mWins; int mLosses; }; /** * Prompts the user for Team Stats * @param aTeam the team stats * @pre empty team stats provided * @post team stats contains the statistics for * a team provided by the user */ void getTeamStats(TeamStats& aTeam); /** * Outputs team stats information * @param aTeam the team stats to be output * @pre aTeam needs to have valid team information * ready for output * @post aTeam's statistical information has been output * to standard output */ void outputTeamStats(const TeamStats& aTeam); /** * Main entry point for the application * @return zero if the application executes successfully */ int main() { TeamStats teamStats[TEAMS]; for(int i = 0; i < TEAMS; i++) { getTeamStats(teamStats[i]); } for(int i = 0; i < TEAMS; i++) { outputTeamStats(teamStats[i]); } return 0; } // pass aTeam by reference because we want to modify aTeam // moreover, we want to allow the user to modify aTeam void getTeamStats(TeamStats& aTeam) { cout << "Please type the team name> "; getline(cin, aTeam.mTeamName); cout << "Please type the number of wins> "; cin >> aTeam.mWins; cout << "Please type the number of losses> "; cin >> aTeam.mLosses; cin.ignore(); } // const param is used here, so that the data in aTeam is marked // as unmutable (can't be changed) // aTeam is passed by reference because it is an object and we // don't want a copy of the data, so we pass by reference // since we don't want the data changed, we use the const modifier void outputTeamStats(const TeamStats& aTeam) { cout << setfill('_') << setw(WIDTH) << " " << endl; cout << aTeam.mTeamName << endl; cout << "Wins: " << aTeam.mWins << endl; cout << "Losses: " << aTeam.mLosses << endl; }