//BowlingMatch.h //ComS 228 Fall 2005 //HW1 #include #include #include using namespace std; #ifndef BOWL_MATCH #define BOWL_MATCH // A struct to hold the information about each frame. // A properly-initialized FrameData variable has the // following properties: // * ball1 is one of '0'...'9' or 'X' or ' ' (space) // * ball2 is one of '0'...'9' or '/' or ' ' // * If ball1 is 'X', then ball2 should be ' ' struct FrameData { char ball1; char ball2; int frameScore; int cumulativeScore; }; // Information about one player and his/her frames. // (Two extra fames are available in case a strike // occurs in the tenth frame.) struct PlayerData { string name; FrameData frames[12]; }; #define TEAMSIZE 4 struct TeamData { string teamName; int teamScore; PlayerData teamMembers[TEAMSIZE]; }; class BowlingMatch { public: BowlingMatch(); //Post: Intializes the two teams with the team names "Team One" and // "Team Two", and the players to "Team One Player 1", "Team One Player // 2", ..., "Team Two Player 1", "Team Two Player 2", etc. All the // balls in all the frames are spaces. All scores are 0. BowlingMatch(string t1name, string t1players[], string t2name, string t2players[]); //Pre: t1players and t2players are both arrays of size TEAMSIZE //Post: Initializes the two teams using t1name and t2name for the team // names and the t1players and t2players for the players' names. All // the balls in all the frames are spaces. All scores are 0. BowlingMatch(ifstream& inFile); //Pre: inFile is formatted like the example input file, and is open // and ready for reading. //Post: The two teams are initialized with the team names, player names, // and frame data as in the file. All scores are 0. void recordResult(int teamNum, string playerName, int frameNum, int ballNum, char result); //Pre: teamNum and ballNum are either 1 or 2, playerName is the name of // one of the players on the team corresponding to teamNum, 1 <= frameNum // <= 12, result is either '0'...'9' or 'X' or '/'. //Post: If the result makes sense for the frame, the frame data is // updated for the given player to the given result. Otherwise, the // frame data is unchanged. ("Makes sense" means that it is a valid // frame entry, given what is already in the frame. For example, an // 'X' result can only happen for ball 1 in the frame and if ball 2 is // a space. A '/' can only happen in ball 2. If ball 1 is 5, then // ball 2 can't be 7. Ball 2 can't be a number if ball 1 is a space.) void computeScores(); //Post: The scores for each frame and the cumulative scores for each // player are computed, and the team scores for both teams are also // computed. void printMatch() const; //Pre: computeScores() has just been called. //Post: All the bowling match information is displayed to the screen // nicely formatted as shown in the example output. string winner() const; //Pre: computeScores() has just been called. //Post: Returns the team name of the team with the highest team score, // or "Tie" if both teams have the same score. private: TeamData team1, team2; }; //end class BowlingMatch #endif