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

CS 1119-91 Programming with C++ Project 6 Write a simple game (program) that two

ID: 3672342 • Letter: C

Question

CS 1119-91 Programming with C++ Project 6
Write a simple game (program) that two people can play. The program prompts the first player to enter an integer greater than or equal to 0, and but not greater than 100. The program then prompts the second player to guess the number that was entered by the first player. When the second player enters the correct number, the program displays an appropriate message and the number of guesses it took to guess the correct number. If the guessed number is less than the correct number, the program outputs the message, "Your guess is lower than the correct number"; otherwise, the program outputs the message "Your guess is higher than the correct number". The program then prompts the second player to enter another number. The second player is prompted to guess the correct number until he or she enters the correct number. Remember, when the program ends, it always outputs the number of guesses it took to guess the correct number.
Your solution must be separated into, at least, three source files (Interface, Implementation, and Test). There should only be minimal code in the Test file -- just enough to instantiate an object, and invoke the appropriate function(s). All prompting for user input, as well as all the statements that receive and manipulate user input must be placed in the implementation file, not in the test file.

Please use 3 files 1 .h 2 .cpp and make sure it works. Please look over the criteria shows you how it should be done.

Please read how it is graded

Compilation errors in your program Program will be rejected. No points.
Not separating your solution into three
files (interface, implementation, and
test files)
-30 points

Do not hard code any user input into
your program. You must prompt for all
input to be provided interactively at
run-time. Otherwise …
-30 points

Your program provides any incorrect
response to the second player’s guesses
-20 points

When the program ends, it outputs
the number of guesses it took to
guess the correct number.
Otherwise…
-10 points

If any code is placed in the Test file
beyond what is needed to
instantiate an object and invoke the
appropriate function(s)…
-30 points

Do not use an instance variable if a
local variable will suffice. For each
unnecessary use of an instance
variable …
-5 points

Allowing the first player to enter a
number that is outside of 0 - 100
-10 points

Any incorrect looping algorithm -20 points
Not terminating the program

correctly, or creating a program that
remains in an infinite loop
-25 points

Thanks

Explanation / Answer

/* Game.h file        */

#ifndef GAME_H
#define GAME_H

class Game
{

public :
void startgame();

};
#endif

/*        Implementation.cpp file               */

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include "Game.h"
using namespace std;

void Game :: startgame()
{
           int number1;
           int player2_guess;
           int attempts;
   printf("Player 1 ");
   printf("enter an integer greater than or equal to 0, and but not greater than 100 ");
   scanf("%d",&number1);
   while(number1<=0 || number1 >=100)
     { printf("incorrect input "); printf("enter integer again ");
     scanf("%d",&number1);
      }

   printf("Player 2 ");
   printf("guess the number entered by player 1 ");
   scanf("%d",&player2_guess);
   attempts = 1;
   while (1)
   {
  
     if(player2_guess > number1 ) printf("Your guess is higher than the correct number ");
     else if(player2_guess < number1) printf("Your guess is lower than the correct number ");
     else break;
     printf ("GUESS AGAIN ");
     scanf("%d",&player2_guess);
     attempts++;
    }

printf("correctAnswer ");
printf("Number of guesses by player2 to guess the number = %d ", attempts );

}

/*               main.cpp          */

#include <iostream>
using namespace std;
#include "Game.h"

int main()
{
      Game game;
      game.startgame();

     return 0;
}

compile the code using the command

g++ -o main main.cpp implementation.cpp

run the code using the command

./main