fork download
  1.  
  2. //Base Class
  3. class Player {
  4.  
  5. public:
  6. virtual int getGuess(){
  7. return 0;
  8. }
  9. }
  10.  
  11. //Human Class to accept the value from human by using getGuess() method
  12. class HumanPlayer : public Player {
  13.  
  14. public:
  15. int getGuess(){
  16. cout<<"Guess the number"
  17. int guess;
  18. cin>>guess;
  19. return guess;
  20. }
  21. }
  22.  
  23.  
  24. // Class to choose the value by Computer by using getGuess() method
  25. class ComputerPlayer : public Player {
  26.  
  27. public:
  28. int getGuess(){
  29. int guess2=rand()%100;
  30. return guess2;
  31. }
  32. }
  33.  
  34.  
  35. class GamePlay {
  36.  
  37. bool checkForWin( int guess, int answer )
  38. {
  39. cout<< “You guessed ” << guess << “.”;
  40. if ( answer == guess )
  41. {
  42. cout<< “You’re right! You win!<<endl;
  43. return true;
  44. }
  45. else if (answer < guess )
  46. cout<< “Your guess is too high.” <<endl;
  47. else
  48. cout<< “Your guess is too low.” <<endl;
  49. return false;
  50. }
  51.  
  52.  
  53.  
  54. void play( Player &player1, Player &player2 )
  55. {
  56. int answer = 0, guess = 0;
  57. answer = rand( ) % 100; // requires <cstdlib>
  58. bool win = false;
  59.  
  60. while( !win )
  61. {
  62. cout<< “Player 1’s turn to guess.” <<endl;
  63. guess = player1.getGuess();
  64. win = checkForWin( guess, answer );
  65. if ( win ) return;
  66. cout<< “Player 2’s turn to guess.” <<endl;
  67. guess = player2.getGuess();
  68. win = checkForWin( guess, answer );
  69. }
  70. }
  71.  
  72. char ch;
  73.  
  74. int main() {
  75.  
  76.  
  77. cout<<"choose 1 :playing game between Human and Computer"
  78. cout<<"choose 2 :playing game between computer and Computer"
  79. cout<<"choose 3 :playing game between Human and Computer"
  80.  
  81. switch(ch) {
  82. case '1' :
  83. HumanPlayer player1;
  84. ComputerPlayer player2;
  85. GamePlay gp;
  86. gp.play(player1,player2);
  87. break;
  88.  
  89. case '2' :
  90. ComputerPlayer player1;
  91. ComputerPlayer player2;
  92. GamePlay gp;
  93. gp.play(player1,player2);
  94. break;
  95.  
  96.  
  97.  
  98. case '3' :
  99. HumanPlayer player1;
  100. HumanPlayer player2;
  101. GamePlay gp;
  102. gp.play(player1,player2);
  103. break;
  104. default: cout<<"u are not specified the correct option"
  105.  
  106. }
  107.  
  108. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:39: error: stray ‘\342’ in program
prog.cpp:39: error: stray ‘\200’ in program
prog.cpp:39: error: stray ‘\234’ in program
prog.cpp:39: error: stray ‘\342’ in program
prog.cpp:39: error: stray ‘\200’ in program
prog.cpp:39: error: stray ‘\235’ in program
prog.cpp:39: error: stray ‘\342’ in program
prog.cpp:39: error: stray ‘\200’ in program
prog.cpp:39: error: stray ‘\234’ in program
prog.cpp:39: error: stray ‘\342’ in program
prog.cpp:39: error: stray ‘\200’ in program
prog.cpp:39: error: stray ‘\235’ in program
prog.cpp:42: error: stray ‘\342’ in program
prog.cpp:42: error: stray ‘\200’ in program
prog.cpp:42: error: stray ‘\234’ in program
prog.cpp:42: error: stray ‘\342’ in program
prog.cpp:42: error: stray ‘\200’ in program
prog.cpp:42: error: stray ‘\231’ in program
prog.cpp:42: error: stray ‘\342’ in program
prog.cpp:42: error: stray ‘\200’ in program
prog.cpp:42: error: stray ‘\235’ in program
prog.cpp:46: error: stray ‘\342’ in program
prog.cpp:46: error: stray ‘\200’ in program
prog.cpp:46: error: stray ‘\234’ in program
prog.cpp:46: error: stray ‘\342’ in program
prog.cpp:46: error: stray ‘\200’ in program
prog.cpp:46: error: stray ‘\235’ in program
prog.cpp:48: error: stray ‘\342’ in program
prog.cpp:48: error: stray ‘\200’ in program
prog.cpp:48: error: stray ‘\234’ in program
prog.cpp:48: error: stray ‘\342’ in program
prog.cpp:48: error: stray ‘\200’ in program
prog.cpp:48: error: stray ‘\235’ in program
prog.cpp:62: error: stray ‘\342’ in program
prog.cpp:62: error: stray ‘\200’ in program
prog.cpp:62: error: stray ‘\234’ in program
prog.cpp:62: error: stray ‘\342’ in program
prog.cpp:62: error: stray ‘\200’ in program
prog.cpp:62: error: stray ‘\231’ in program
prog.cpp:62: error: stray ‘\342’ in program
prog.cpp:62: error: stray ‘\200’ in program
prog.cpp:62: error: stray ‘\235’ in program
prog.cpp:66: error: stray ‘\342’ in program
prog.cpp:66: error: stray ‘\200’ in program
prog.cpp:66: error: stray ‘\234’ in program
prog.cpp:66: error: stray ‘\342’ in program
prog.cpp:66: error: stray ‘\200’ in program
prog.cpp:66: error: stray ‘\231’ in program
prog.cpp:66: error: stray ‘\342’ in program
prog.cpp:66: error: stray ‘\200’ in program
prog.cpp:66: error: stray ‘\235’ in program
prog.cpp: In member function ‘virtual int HumanPlayer::getGuess()’:
prog.cpp:16: error: ‘cout’ was not declared in this scope
prog.cpp:17: error: expected `;' before ‘int’
prog.cpp:18: error: ‘cin’ was not declared in this scope
prog.cpp:18: error: ‘guess’ was not declared in this scope
prog.cpp: In member function ‘virtual int ComputerPlayer::getGuess()’:
prog.cpp:29: error: ‘rand’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:108: error: expected `}' at end of input
prog.cpp: In member function ‘bool GamePlay::checkForWin(int, int)’:
prog.cpp:39: error: ‘cout’ was not declared in this scope
prog.cpp:39: error: ‘You’ was not declared in this scope
prog.cpp:39: error: expected `;' before ‘guessed’
prog.cpp:42: error: expected `;' before ‘re’
prog.cpp:46: error: ‘Your’ was not declared in this scope
prog.cpp:46: error: expected `;' before ‘guess’
prog.cpp:48: error: ‘Your’ was not declared in this scope
prog.cpp:48: error: expected `;' before ‘guess’
prog.cpp: In member function ‘void GamePlay::play(Player&, Player&)’:
prog.cpp:57: error: ‘rand’ was not declared in this scope
prog.cpp:62: error: ‘cout’ was not declared in this scope
prog.cpp:62: error: expected primary-expression before numeric constant
prog.cpp:62: error: expected `;' before numeric constant
prog.cpp:66: error: expected primary-expression before numeric constant
prog.cpp:66: error: expected `;' before numeric constant
prog.cpp: In member function ‘int GamePlay::main()’:
prog.cpp:77: error: ‘cout’ was not declared in this scope
prog.cpp:78: error: expected `;' before ‘cout’
prog.cpp:108: warning: no return statement in function returning non-void
prog.cpp: At global scope:
prog.cpp:108: error: expected unqualified-id at end of input
stdout
Standard output is empty