Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code in c++ NOTE: Put your function prototypes in a header file called play.h, function definitions in an implementation file called play.cpp, and have main

Code in c++

NOTE:

Put your function prototypes in a header file called play.h, function definitions in an

implementation file called play.cpp, and have main only have the main function (be sure to use in

your main and play.cpp: #include play.h)

IMPORTANT NOTE #1

:

Make sure and use the required functions as indicated in the

instructions for this program! Use value returning functions where asked for ( this is

REQUIRED - I want to make sure people understand value returning functions, void functions

are overused and are more procedural, I want to get away from that). NO GLOBALS and

unless specifically asked for (THEY ARE NOT AND WILL NOT BE ASKED FOR) and no void

functions (unless specifically asked for).

*IMPORTANT NOTE #2:

Do NOT make a USELESS value returning function that is merely a

"void" function with a return on it.

PROGRAM 1

You are going to write a program that allows the user to play a game of

Rock Paper Scissors

against the

computer.

The general game of

Rock Paper Scissors

works as follows

1.

First both players choose Rock, Paper or Scissors (a player cannot see the other players choice until they

have made their choice)

2.

Next a winner is determined based on the following rules (these are the ONLY ways you can win the game

if you didnt win and you didnt tie you lost):

If one player chooses Rock and the other player chooses Scissors, then Rock wins

o

The game then prints a message to the user indicating they won

If one player chooses Scissors and the other player chooses Paper, then Scissors wins

o

The game then prints a message to the user indicating they won

If one player chooses Paper and the other player chooses Rock, then Paper wins

o

The game then prints a message to the user indicating they won

If both players make the same choice the result is a tie and the game will print a message saying the

game was a tie

The program should begin by displaying the following menu:

ROCK PAPER SCISSORS MENU

-------------------------

p)Play Game

q)Quit

-

If the user selects p:

1.

First the program should call a function named

getComputerChoice

to get the computers choice in the

game. The

getComputerChoice

function should generate a random number between 1 and 3. If the random

number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the

random number is 3 the computer has chosen Scissors. (

Hint:

one way to do this is to return an

int

from

the function and make the function have no arguments).

This function is REQUIRED to be a value

returning function (do NOT make a void function). Also, do NOT put in srand(time(NULL)) in that

function, put it in as the first statement in main.

2.

Next the program should call a function named

getPlayerChoice

to get the users (players) choice in the

game. Have the users choice be represented by a number just like the computers was. The

getPlayerChoice

function should display a menu similar to the one below and then get a 1, 2, or 3 as the

users choice for Rock, Paper or Scissors. Do not allow the user to enter an invalid choice they must enter

1, 2, or 3 (use integers for the menu on this instead of chars). (

Hint:

one way to implement this function is

to return an

int

from the function and make the function have no arguments).

This function is

REQUIRED to be a value returning function (do NOT make a void function).

Rock, Paper or Scissors?

1) Rock

2) Paper

3) Scissors

Please enter your choice:

3. Next the program should display what the user chose and what the computer chose. You will need to

convert both the users and the computers integer choices of 1, 2, or 3 to the corresponding strings: Rock,

Paper, or Scissors. The display should be similar to the following (in the example below the user chose 3

for Scissors and the computer chose 2 for Paper):

You chose: Scissors

The computer chose: Paper

4. Next the program should call a function named

isTie

(Hint:

one way to do this is to have the function

return a bool and take two arguments

)

to see if the game was a tie.

This function is REQUIRED to be a

value returning function (do NOT make a void function).

The game is a tie if both the computer and user

made the same choice. If the game was a tie display the appropriate message. An example of a tie is shown

below with the appropriate message on the third line.

You choose: Scissors

The computer chose: Scissors

It's a TIE!

5. If the game was NOT a tie, the program should next determine if the player (user) has won the game. You

should use a function called

isPlayerWinner

to do this, the function should take two arguments (the player

choice and the computer choice and return a bool: true if the player is a winner and false if the player is not

a winner).

This function is REQUIRED to be a value returning function (do NOT make a void function).

After calling the function, cased on the result of it, if the player has won the program should display a

message similar to the one below telling the user they won. In the example below the users winning

choice is

Rock

and the computers losing choice is

Scissors

. (Remember the rules for winning and losing

are at the top of the page)

You choose: Rock

The computer chose: Scissors

You WIN!

6. If the game was NOT a tie and the user (player) did NOT win this means the computer won and the program

should display a message saying the user has lost. In the example below the computers winning choice is

Paper

(the users losing choice is

Rock

). Do not make this complicated, if it was not a tie and the player did

not win the computer won.

You choose: Rock

The computer chose: Paper

Sorry you LOSE.

-If the user selects q:

Quit the program

-If the user selects anything other than p or q:

Display an error message.

-

The program should keep redisplaying the menu and let the user play as many games against the computer as

they would like

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions