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