C++: Program 5 Rock, Paper, Scissors Using pointers, references, rand and overloaded functions This will be a multi-file program. Your main will be in Driver.cpp, your function prototypes will go in Functions.h, and your function definitions will go in Functions.cpp.  You will also create a struct to hold the GameData.  It will be defined in the .h file, before the prototypes. struct GameData {        int tieCount = 0;        int numRounds = 0;                                                                                  int userWins = 0;        int compWins = 0;        int numGames = 0; }; For this assignment, you are going to program the “Rock, Paper, Scissors” game.  The user will play against the computer.  A scissor can cut paper, a rock can knock a scissor, and pap

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

C++: Program 5 Rock, Paper, Scissors

Using pointers, references, rand and overloaded functions

This will be a multi-file program. Your main will be in Driver.cpp, your function prototypes will go in Functions.h, and your function definitions will go in Functions.cpp.  You will also create a struct to hold the GameData.  It will be defined in the .h file, before the prototypes.

struct GameData

{

       int tieCount = 0;

       int numRounds = 0;                                                                          

       int userWins = 0;

       int compWins = 0;

       int numGames = 0;

};

For this assignment, you are going to program the “Rock, Paper, Scissors” game.  The user will play against the computer.  A scissor can cut paper, a rock can knock a scissor, and paper can wrap a rock.   One game of the Rock Paper Scissors will be such that your user will play continuously until the user or computer wins two times. That is, the game will stop when one of the players wins two rounds. The user may play as many games as they like.

  1. When your program begins, seed the rand with the system time and show your course header and game explanation by calling the WriteHeader and WriteGameRules Then open a do-while loop so the player can play the game as many times as they like. You will also have an inner do while loop for the play loop that runs until the user or the computer has won twice.
  2. Ask the user to select their choice (rock, paper, scissors) by calling the AskUserChoice function which displays a menu and asks the user to enter a number. Pass in a pointer for the user’s choice.
  3. Make sure the user’s choice is valid by passing it to the ValidateUserChoice If it is within the menu range, then return true. If not, build an error message to the user including the choice they entered and return it by the string pointer that was passed in and return false.
  4. If the user’s choice is valid, then the game play will continue by calling the ObtainCompChoice It is passed the user’s choice, a pointer for the computer’s choice, and a reference to the GameData object that contains the counter for ties. The program uses a random number generator to obtain the computer’s selection. Ties do not count toward the game play, so make sure the computer number is not the same as the user number before exiting the function. However, you should keep a tally of the ties for display purposes.
  5. After obtaining the computer’s choice you will need to evaluate who won by calling the DetermineWinner This function is passed the user choice, computer choice, and references to the GameData object that contains counters for user and computer wins. You will determine the winner based on the game rules, increment the winner’s tally, and build a message to the user that is returned to main. The message reports both the computer’s and user’s object, and who won that round. DetermineObject will be called from this function to get each player’s object name. It will be passed the player’s menu choice and a reference to the object string.
  6. Report the results of that round to the user by calling the WriteResults that is passed the result string, ties, user wins, and computer wins. Be sure to include number of valid rounds, wins for each player, and number of disallowed ties in the report.
  7. If the user’s choice is not valid, call the WriteResults that is passed the result error message string. After the message is displayed, the loop will start over.
  8. When one of the players has won two rounds, report the number of games played and who won the game, then ask if the user would like to play again. Be specific about how the user should answer. If the answer is yes, start the next game. When the user is done playing games, give a good bye message.

The functions you will need are:

 

Return Type

Function Name

Argument List

Description

void

WriteHeader

(  )

Display the course header and any additional information to the user.

void

WriteGameRules

( )

Display the rules of the game.

void

AskUserChoice

(int *p_uChoice)

Display a menu and allow the user to select a weapon type

bool

ValidateUserChoice

(int uChoice, string *p_result)

Verify that the user’s choice is within the menu range. If not, build a message to the user including the number they chose.

void

ObtainCompChoice

(int uChoice, int *p_cChoice, GameData &r_data)

Obtain the computer’s choice using rand(), but avoid matching the user’s choice. Keep a tally of the times it tries to tie.

string

DetermineWinner

(int uChoice, int cChoice, GameData &r_data)

Determines the winner based on the game rules, increments the winner’s tally, and builds a string message to the user.

void

DetermineObject

(int choice, string &r_object)

Determines whether numeric choice is a rock, paper, or scissors and assigns it to a string.

void

WriteResults

(string result, GameData data)

Display the result string plus valid rounds, user wins, computer wins, and ties.

void

WriteResults

(string result)

Display the result error message string.

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY