Question

In: Computer Science

Develop a C++ program that plays out a round of Rock, Paper, Scissors using Functional Programming...

Develop a C++ program that plays out a round of Rock, Paper, Scissors using Functional Programming

1) Develop a function that prompts the user to enter their choice (1=Rock 2=Paper 3=Scissors)

  • Return either a 1, 2, or 3 depending on the value the user has entered
  • Do not continue the program until the user has entered a valid choice of 1, 2, 3

2) Develop a function that generates the computer player's choice

  • Return either a 1, 2, or 3 depending on random number generation

3) Develop a function that displays which player won the game round

  • Display the computer's choice here in this function
  • Rock (1) beats scissors(3)
  • Scissors(3) beats paper (2)
  • Paper(2) beats rock (1)
  • Ties should be displayed (1,1) (2,2) (3,3)

4) Develop your main function to play one round of RPS versus a randomized computer opponent

Solutions

Expert Solution

input code:

output:

code:

#include <iostream>
using namespace std;
int user_choice()
{
/*declare the variable*/
int choice;
/*print menu*/
cout<<"1.Rock\n2.Paper\n3.Scissors\nEnter your choice:";
/*take user input*/
cin>>choice;
/*return input*/
return choice;
}
/*computer_choice*/
int computer_choice()
{
/*seed the value*/
srand(time(NULL));
/*return choice*/
return rand()%3+1;
}
void win(int u,int c)
{
/*if user choice Rock*/
if(u==1)
{
/*if Computer choice Rock*/
if(c==1)
{
/*print tie*/
cout<<"----Tie----";
}
/*if Computer choice Paper*/
else if(c==2)
{
/*Computer win*/
cout<<"Paper beat Rock....Computer win";
}
/*if Computer choice Scissors*/
else
{
/*player win*/
cout<<"Rock beat Scissors.....User win";
}
}
/*if user choice Paper*/
else if(u==2)
{
/*if Computer choice rock*/
if(c==1)
{
/*player win*/
cout<<"Paper beat Rock....User win";
}
/*if Computer choice Paper*/
else if(c==2)
{
/*print tie*/
cout<<"----Tie----";
}
/*if Computer choice Scissors*/
else
{
/*Computer win*/
cout<<"Scissors beat Paper.....Computer win";
}
}
/*if user choice Scissors*/
else if(u==3)
{
/*if Computer choice rock*/
if(c==1)
{
/*Computer win*/
cout<<"Rock beat Scissors.....Computer win";
}
/*if Computer choice Paper*/
else if(c==2)
{
/*player win*/
cout<<"Scissors beat Paper....User win";
}
else
/*if Computer choice Scissors*/
{
/*print tie*/
cout<<"----Tie----";
}
}
else
{
/*print Invalid if none of them*/
cout<<"Invalid user input";
}
}
int main()
{
/*call function and store input*/
int u=user_choice();
int c=computer_choice();

/*call win function*/
win(u,c);
return 0;
}


Related Solutions

Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a...
Write a Java program that plays the game Rock, Paper, Scissors. The program should generate a random choice (Rock, Paper or Scissors) then ask the user to choose Rock, Paper or Scissors. After that the program will display its choice and a message showing if the player won, lost or tied. Next, the program should prompt the user to play again or not. Once the player selects to stop playing the game, the program should print the number of wins,...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an int field called strength and a char field called type. You may make them either private or protected. The Tool class should also contain the function void setStrength(int), which sets the strength for the Tool. Create 3 more classes called Rock, Paper, and Scissors, which inherit from Tool. Each of these classes will need a default constructor that sets the strength to 1 and...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When...
JAVA : Design and implement an application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then prompt for the user’s selection. At that point, the program...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the...
One file java program that will simulate a game of Rock, Paper, Scissors. One of the two players will be the computer. The program will start by asking how many winning rounds are needed to win the game. Each round will consist of you asking the user to pick between rock, paper, and scissors. Internally you will get the computers choice by using a random number generator. Rock beats Scissors, Paper beats Rock, and Scissors beats Paper. You will report...
Rock Paper Scissors Lizards Spock IN JAVASCRIPT! Purpose The purpose of this program is for students...
Rock Paper Scissors Lizards Spock IN JAVASCRIPT! Purpose The purpose of this program is for students to demonstrate their understanding of selection. The program can be developed using if-statements with no logical operators. Hint: Use nested-if statements to help you construct the logic of the program. Rules and Structure of Program Rock Paper Scissors Lizard Spock is similar to the traditional two-player game Rock-Paper-Scissors with two additional game items to select. You will develop a program that replicates this game....
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played...
Design and implement an Android application that plays the Rock-Paper-Scissors game against the computer. When played between two people, each person picks one of three options (usually shown by a hand gesture) at the same time, and a winner is determined. In the game, Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. The program should randomly choose one of the three options (without revealing it) and then seek for the user’s selection (using your choice of an object...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11...
Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11 in Chapter 6 asked you to design a program that plays the Rock, Paper, Scissors game. In the program, the user enters one of the three strings—"rock", "paper", or "scissors"—at the keyboard. Add input validation (with a case-insensitive comparison) to make sure the user enters one of those strings only. Modifications: Allow the user to input "r", "p", "s" or the full strings "Rock",...
write a python script for rock scissors paper game
write a python script for rock scissors paper game
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game...
Rock, Paper, Scissors Game Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: You can set these constant global variables at the top outside of your main function definition: COMPUTER_WINS = 1 PLAYER_WINS = 2 TIE = 0 INVALID = 3 ROCK = 1 PAPER = 2 SCISSORS = 3 For this program 1 represents rock, 2 represents paper, and 3 represents scissors. In...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper,...
In the game Rock Paper Scissors, two players simultaneously choose one of three options: rock, paper, or scissors. If both players choose the same option, then the result is a tie. However, if they choose differently, the winner is determined as follows: • Rock beats scissors, because a rock can break a pair of scissors. • Scissors beats paper, because scissors can cut paper. • Paper beats rock, because a piece of paper can cover a rock. Create a game...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT