In: Computer Science
Write in C++
Abstract/Virtual Rock Paper Scissors
Create an abstract Player class that consists of private data for name, selection, wins, and losses. It must have a non-default constructor that requires name. It may not contain a default constructor. Create overloaded functions for the ++ and - - operator. The overloaded ++operator will add to the number of wins, while the - - operator will add to the losses.
You will create two different child classes of player, Human and Computer. Neither of which will have any private data, as they will use the parent’s data. Both will contain a virtual function called makeSelection() that will determine and set the selection for the particular player.
Your main() program will contain a NON-member function called playGame() that will take in your two players. You should ask the user if they would like to pay against another human, or a computer, or if they would like to see two computers play.
You will then need to create the appropriate objects and start the game play. After each round, you must display the number of wins and losses for each player and continue playing the game until the user decides to quit.
Hi, here is the solution. Try it out and let me know if you need any changes.
/* #ifndef PLAYER_H_ #include <iostream> using namespace std; class Player void setLosses(int losses) const string& getName() const void setName(const string &name) char getSelection() const int getWins() const void setWins(int wins) void setSelection(char selection)
class Human: public Player }; }; |
/* #include "Player.h" Player::Player(string name) Player& Player::operator ++() Player& Player::operator --() Human::Human(string name):Player(name) Computer::Computer(string name):Player(name)
char Computer::makeSelection() } |
/* #include "Player.h" void playGame(Player & p1, Player & p2) exit = false;
|