Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

zyBooks offers more resources to help you. NEED EXTRA PRAC 15.23 Activity Apr 27

ID: 3827032 • Letter: Z

Question

zyBooks offers more resources to help you. NEED EXTRA PRAC 15.23 Activity Apr 27 Students. This content is controlled by your instructor and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the "Trouble with lab?" button at the bottom of the lab. Implement the RPs game (Rock, Paper, Scissors) Rock breaks Scissors Paper covers Rock Scissors cuts Paper Player class Private member variable int choice o 1: Rock o 2: Paper o 3: Scissor function play() Human Player class Inherits Player Redefine play() function Ask user for input o Input can be "R", "P", "S" for "Rock", "Paper", "Scissor" o Convert input to number and store in choice variable ComputerPlayer class Inherits Player Redefine play0 function o Generate random number between 1 and 3 (inclusive)

Explanation / Answer

#include <iostream>

#include <cstdlib>


using namespace std;


class Player{
  
private:
int choice;
  
public:
void play();
};


class Human : public Player {
  
  
int play(){
char a;
int b,c;
  
cout<<" Enter the input ";
cin>>a;
b=int(a); /*Type cast to convert char to int */
/*cout << "ASCII Value of " << a << " is " << int(a); */
if(b==82){
c=1; /*ASCII of "R" is 82 */
else if(b==80)
c=2; /*ASCII of "P" is 80*/
else if(b==83)
c=3; /*ASCII of "S" is 83*/
else
cout<<"Wrong Input";
}
  
return c;
  
  
};

class Computer : public Player{
  
int play(){
  
srand(time(NULL));
int randNum = (rand() % 3) + 1; /*To generate a number between 1 to 3 both inclusive */
return randNum;
};

void determineWinner(Player &a, Player &b)
{
int c1=a.play();
int c2=b.play();
  
if(c1==c2){
cout<<" Tie";
  
else if(c1==1 && c2==2)
cout<<" Winner(Computer)";
  
else if(c1==1 && c2==3)
cout<<" Winner(Player)";
  
else if(c1==2 && c2==1)
cout<<" Winner(Player)";
  
else if(c1==2 && c2==3)
cout<<" Winner(Computer)";
  
else if(c1==3 && c2==1)
cout<<" Winner(Computer)";
  
else if(c1==3 && c2==2)
cout<<" Winner(Player)";
}
else
cout<<" Wrong Input";
}

int main()

{
srand(1);
Computer comp;
Human human;

determineWinner(human,comp);

determineWinner(comp,comp);


return 0;
}