Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

EASY CLASS IMPLEMENTATION CODE, NEED MAIN.CPP, RPSLSTYPE.H, RPSLSIMP.CPP. RUN ONE STAGE AFTER ANOTHER IN MAIN.CPP, COMPILED EXAMPLE BELOW NEEDS MAIN FILE TO OUTPUT FOLLOWING COMPILED

EASY CLASS IMPLEMENTATION CODE, NEED MAIN.CPP, RPSLSTYPE.H, RPSLSIMP.CPP.

RUN ONE STAGE AFTER ANOTHER IN MAIN.CPP, COMPILED EXAMPLE BELOW

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

NEEDS MAIN FILE TO OUTPUT FOLLOWING COMPILED CODE SHOWN

CS 202 - Assignment #2 Purpose: Due: Points: Learn simple class implementation. Sunday (209) 100 Rock Assignment: The game Rock-Paper-Scissors. is a two-person hand game. The game is often used as a selection method similar to coin flipping or drawing straws to randomly select a winner. However, unlike truly random selections, if the game extends over many sessions, a Lizard Paper Je player can often recognize and exploit the non-random behavior of an opponent. Spock Scissors A popular extension is the Rock-Paper-Scissors-Lizard- Spock' game and was featured on the television show Big Bang Theory. This extension adds a significant Scissors cuts Paper covers Rock crushes number of additional possible outcomes and is thus Lizard poisons Spock smashes Scissors more random decapitates Lizard eats Paper disproves Spock vaporizes Rock crushes Scissors, Design and implement a C++ class for the Rock-Paper- Scissors-Lizard-Spock (RPSLS) game. The class will incorporate all functions and data required for the game, including multi-game tracking (e.g., games played, wins, losses, ties). The rpsls Type UML class diagram is as follows: rpslsType -userWins: int -userLosses: int -games Played: int + pels Type() +play Round(): void +showScores(): void +reset Scores(): void +playAgain(): bool +get Scores (int &, int &, int k): void -showRound(): void -getUserMove (): int -getComputerMove (): int The header file is provided. You will need to develop an implementation file based on the above UML diagram (which is represented in the provided header file). Your implementation and header files should be fully commented. Function Descriptions: The following are more detailed descriptions of the required functions. The rpsls Type() constructor should initialize the class variables (all O's for this object). The showScores() function should display the score statistics to the screen. The format should closely match the provided examples. The resetScores() mutator function should reset the class variables for score tracking (to O's). The getScores(int &, int &, int &) const accessor function should return the games played, user wins, and user losses in that order) via reference. The boolean playAgain() function should prompt the user if they want to play again. The function should read 'Y'/y/N' and return true for 'Y/y' and false for N'. If invalid input is entered, the function should provide an error message and re-prompt. Refer to the example executions for the formatting and error messages. The playRound() function should play a single round of Rock-Paper-Scissors-Lizard-Spock. This will involve getting the user move (via getUser Move( function) and then the get computer move (via the getComputer Move() function). Based on that information, the function should select a winner, display the results, and update the applicable class variables for games played, user wins, or user loss. Choose winner based on the following rules: Scissors cut paper, Paper covers rock. Rock crushes lizard. Lizard poisons Spock. Spock smashes scissors, Scissors decapitate lizard. Lizard eats paper. Paper disproves Spock. Spock vaporizes rock. Rock crushes scissors. Note, the function will be reviewed for efficiency. An overly complex approach will be marked down significantly The private integer getComputer Move() function should use the C++ rand function to select the computer move by returning an integer between 1 and 5 (inclusive) The private integer getUser Moved function should prompt the user for a move selection ('1' - '5, '1-Rock, '2'=Paper, 3'-Scissors, 4'-Lizard, and '5'=Spock). The function must ensure that the user selection is between '1'-'5. If correct input is received, the function should return the integer (between 1 and 5, inclusive). If incorrect input is entered, the function should should display an error message and re-prompt. The function must be able to handle invalid input, including invalid character input (i.e., if user enters a 'R', which is incorrect/invalid). Refer to the example executions for output formatting. Make sure your program includes the appropriate documentation. See Program Evaluation Criteria for CS 202. Submission: When complete, submit: A copy of the source files (i.e., main.cpp, rpslsType.h, and rpsisImp.cpp) via the class web page (assignment submission link) by class time on the due date. Example Executions: Below is an example program execution showing the I/O formatting. ed-ubuntu: ../ast02 . . . . . . . . . . . . . . . . . . . . . . . CS 202 - Assignment #2 Rock Paper Scissors Lizard Spock Game Stage 1 - Best of 5 games Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Rock crushes lizard. You win! Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 2 Tie! Please try again! Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Tie! Please try again! Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : 0 Error, invalid input. ------------------- Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 1 Rock crushes lizard. Sorry, you lose. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : five Error, invalid input. ----------- Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 5 Scissors decapitate lizard. You win! Score Summary Games Played: 5 User wins: 2 User losses: 1 Game Ties: 2 Stage 2 - Unlimited Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Tie! Please try again! Play again (Y/y/N): 9 Error, invalid response. Plese re-enter. Play again (Y/y/N): 4 Error, invalid response. Plese re-enter. Play again (Y/y/N): Y Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : 2 Tie! Please try again! Play again (Y/y/N): Y Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : 1 Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 3 Tie! Please try again! Play again (Y/y/N): n Score Summary Games Played: 3 User wins: 0 User losses: 0 Game Ties: 3 EFE Stage 1 - One game, All-or-Nothing Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Spock smashes scissors. Sorry, you lose. Spock smashes scissors. Sorry, you lose. Score Summary Games Played: 1 User wins: 0 User losses: 1 Game Ties: 0 Program Terminated ed-ubuntu: // Rock-Paper-Scissors-Lizard-Spock game class header file. // Includes. #include using namespace std; // ****************************************************************** // Rock-Paper-Scissors-Lizard-Spock class declaration. class rpslsType public: // Constructor - initialize class variables. rpslsType(); // Play a round -> user move, computer move, update scores, // and show results (as per examples). void play Round(); // Show formatted scores (see example). void showScores(); // Reset all scores (to O's). void reset Scores(); // Ask user of they want to play again (Y/y/N). // For invalid input, display error message and reprompt. bool playAgain(); // Get and return current values for score variables. // gamesPlayed, userWins, and userLosses (in that order). void getScores(int &, int &, int & const; private: // Prompt for and read user move. // For invalid input, display error message and reprompt. // Must be able to handle character input. // Returns 1-5 (inclusive). int getUserMove(); // Get computer move (random, 1-5). int getComputerMove(); int int int gamesPlayed; userWins; userLosses; // total games played // count of games the user won // count of games the user lost // Includes and prototypes. #include #include #include #include "rpslsType.h" using namespace std; // ***** // Rock-Paper-Scissors-Lizard-Spock implentation functions. // -------------------------- --------- ------- // Rock-Paper-Scissors-Lizard-Spock constructors. rpslsType: :rpslsType() } // -------- --------- ------------------ --------- // Play a round -> user move, computer move, update scores. void rpslsType: :playRound() // // ---------- Show score. void rpslsType::showScores) // ----------- // Reset all scores. void rpslsType: :resetScores) void rpslsType::getScores(int &gp, int &uw, int &ul) const // ------- // Get computer move (random). int rpslsType::getComputerMove() // ------ // Ask user of they want to play again. bool rpslsType: :playAgain() // --------------- // Prompt for and read user move. int rpslsType::getUserMove() # Make file for RPSLS Program. OBJS = main.orpsls Imp. CC = g++ -Wall -pedantic - Wextra-std=c++11 -g all: main main: $ (OBJS) $ (CC) -o main $ (OBJS) main.o: main.cpp rpslsType.h $ (CC) -c main.cpp rpsls Imp.o: rpslsImp.cpp rpslsType.h $ (CC) -c rpsls Imp.cpp # ----- # clean by removing object files. clean: rm S (OBJS) CS 202 - Assignment #2 Purpose: Due: Points: Learn simple class implementation. Sunday (209) 100 Rock Assignment: The game Rock-Paper-Scissors. is a two-person hand game. The game is often used as a selection method similar to coin flipping or drawing straws to randomly select a winner. However, unlike truly random selections, if the game extends over many sessions, a Lizard Paper Je player can often recognize and exploit the non-random behavior of an opponent. Spock Scissors A popular extension is the Rock-Paper-Scissors-Lizard- Spock' game and was featured on the television show Big Bang Theory. This extension adds a significant Scissors cuts Paper covers Rock crushes number of additional possible outcomes and is thus Lizard poisons Spock smashes Scissors more random decapitates Lizard eats Paper disproves Spock vaporizes Rock crushes Scissors, Design and implement a C++ class for the Rock-Paper- Scissors-Lizard-Spock (RPSLS) game. The class will incorporate all functions and data required for the game, including multi-game tracking (e.g., games played, wins, losses, ties). The rpsls Type UML class diagram is as follows: rpslsType -userWins: int -userLosses: int -games Played: int + pels Type() +play Round(): void +showScores(): void +reset Scores(): void +playAgain(): bool +get Scores (int &, int &, int k): void -showRound(): void -getUserMove (): int -getComputerMove (): int The header file is provided. You will need to develop an implementation file based on the above UML diagram (which is represented in the provided header file). Your implementation and header files should be fully commented. Function Descriptions: The following are more detailed descriptions of the required functions. The rpsls Type() constructor should initialize the class variables (all O's for this object). The showScores() function should display the score statistics to the screen. The format should closely match the provided examples. The resetScores() mutator function should reset the class variables for score tracking (to O's). The getScores(int &, int &, int &) const accessor function should return the games played, user wins, and user losses in that order) via reference. The boolean playAgain() function should prompt the user if they want to play again. The function should read 'Y'/y/N' and return true for 'Y/y' and false for N'. If invalid input is entered, the function should provide an error message and re-prompt. Refer to the example executions for the formatting and error messages. The playRound() function should play a single round of Rock-Paper-Scissors-Lizard-Spock. This will involve getting the user move (via getUser Move( function) and then the get computer move (via the getComputer Move() function). Based on that information, the function should select a winner, display the results, and update the applicable class variables for games played, user wins, or user loss. Choose winner based on the following rules: Scissors cut paper, Paper covers rock. Rock crushes lizard. Lizard poisons Spock. Spock smashes scissors, Scissors decapitate lizard. Lizard eats paper. Paper disproves Spock. Spock vaporizes rock. Rock crushes scissors. Note, the function will be reviewed for efficiency. An overly complex approach will be marked down significantly The private integer getComputer Move() function should use the C++ rand function to select the computer move by returning an integer between 1 and 5 (inclusive) The private integer getUser Moved function should prompt the user for a move selection ('1' - '5, '1-Rock, '2'=Paper, 3'-Scissors, 4'-Lizard, and '5'=Spock). The function must ensure that the user selection is between '1'-'5. If correct input is received, the function should return the integer (between 1 and 5, inclusive). If incorrect input is entered, the function should should display an error message and re-prompt. The function must be able to handle invalid input, including invalid character input (i.e., if user enters a 'R', which is incorrect/invalid). Refer to the example executions for output formatting. Make sure your program includes the appropriate documentation. See Program Evaluation Criteria for CS 202. Submission: When complete, submit: A copy of the source files (i.e., main.cpp, rpslsType.h, and rpsisImp.cpp) via the class web page (assignment submission link) by class time on the due date. Example Executions: Below is an example program execution showing the I/O formatting. ed-ubuntu: ../ast02 . . . . . . . . . . . . . . . . . . . . . . . CS 202 - Assignment #2 Rock Paper Scissors Lizard Spock Game Stage 1 - Best of 5 games Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Rock crushes lizard. You win! Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 2 Tie! Please try again! Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Tie! Please try again! Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : 0 Error, invalid input. ------------------- Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 1 Rock crushes lizard. Sorry, you lose. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : five Error, invalid input. ----------- Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 5 Scissors decapitate lizard. You win! Score Summary Games Played: 5 User wins: 2 User losses: 1 Game Ties: 2 Stage 2 - Unlimited Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Tie! Please try again! Play again (Y/y/N): 9 Error, invalid response. Plese re-enter. Play again (Y/y/N): 4 Error, invalid response. Plese re-enter. Play again (Y/y/N): Y Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : 2 Tie! Please try again! Play again (Y/y/N): Y Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : 1 Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock : Error, invalid input. Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock 3 Tie! Please try again! Play again (Y/y/N): n Score Summary Games Played: 3 User wins: 0 User losses: 0 Game Ties: 3 EFE Stage 1 - One game, All-or-Nothing Enter Move 1 - Rock 2 - Paper 3 - Scissors 4 - Lizard 5 - Spock Spock smashes scissors. Sorry, you lose. Spock smashes scissors. Sorry, you lose. Score Summary Games Played: 1 User wins: 0 User losses: 1 Game Ties: 0 Program Terminated ed-ubuntu: // Rock-Paper-Scissors-Lizard-Spock game class header file. // Includes. #include using namespace std; // ****************************************************************** // Rock-Paper-Scissors-Lizard-Spock class declaration. class rpslsType public: // Constructor - initialize class variables. rpslsType(); // Play a round -> user move, computer move, update scores, // and show results (as per examples). void play Round(); // Show formatted scores (see example). void showScores(); // Reset all scores (to O's). void reset Scores(); // Ask user of they want to play again (Y/y/N). // For invalid input, display error message and reprompt. bool playAgain(); // Get and return current values for score variables. // gamesPlayed, userWins, and userLosses (in that order). void getScores(int &, int &, int & const; private: // Prompt for and read user move. // For invalid input, display error message and reprompt. // Must be able to handle character input. // Returns 1-5 (inclusive). int getUserMove(); // Get computer move (random, 1-5). int getComputerMove(); int int int gamesPlayed; userWins; userLosses; // total games played // count of games the user won // count of games the user lost // Includes and prototypes. #include #include #include #include "rpslsType.h" using namespace std; // ***** // Rock-Paper-Scissors-Lizard-Spock implentation functions. // -------------------------- --------- ------- // Rock-Paper-Scissors-Lizard-Spock constructors. rpslsType: :rpslsType() } // -------- --------- ------------------ --------- // Play a round -> user move, computer move, update scores. void rpslsType: :playRound() // // ---------- Show score. void rpslsType::showScores) // ----------- // Reset all scores. void rpslsType: :resetScores) void rpslsType::getScores(int &gp, int &uw, int &ul) const // ------- // Get computer move (random). int rpslsType::getComputerMove() // ------ // Ask user of they want to play again. bool rpslsType: :playAgain() // --------------- // Prompt for and read user move. int rpslsType::getUserMove() # Make file for RPSLS Program. OBJS = main.orpsls Imp. CC = g++ -Wall -pedantic - Wextra-std=c++11 -g all: main main: $ (OBJS) $ (CC) -o main $ (OBJS) main.o: main.cpp rpslsType.h $ (CC) -c main.cpp rpsls Imp.o: rpslsImp.cpp rpslsType.h $ (CC) -c rpsls Imp.cpp # ----- # clean by removing object files. clean: rm S (OBJS)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions