Menu
support@authoritypapers.com
+1(805) 568 7317

in this project you will write a complete program that allows the user to play a gam 5192348

In this project, you will write a complete program that allows the user to play a game of Mastermind against the computer. A Mastermind game has the following steps:

1. The codebreaker is prompted to enter two integers: the code length n, and the range of digits m.

2. The codemaker selects a code: a random sequence of n digits, each of which is in the range [0,m-1].

3. The codebreaker is prompted to enter a guess, an n-digit sequence.

4. The codemaker responds by printing two values that indicate how close the guess is to the code. The first response value is the number of digits that are the right digit in the right location. The second response value is the number of digits that are the right digit in the wrong location. For example if the code is 1, 2, 3, 4, 5 and the guess is 5, 0, 3, 2, 6, the response would be 1, 2 because one digit (3) is the right digit in the right location, and two digits (2 and 5) are the right digits in the wrong locations. Note that no digit in the code or guess is counted more than once. If the code is 1, 2, 3, 4, 5 and the guess is 2, 1, 2, 2, 2, the response is 0, 2. If the code is 3, 2, 3, 3, 3 and the guess is 1, 3, 3, 4, 5, the response is 1, 1.

5. The codebreaker is prompted to continue entering guesses. The codebreaker wins if the correct code is guessed in ten or fewer guesses, and otherwise the codemaker wins.

I have a code that contains the following parts of the program:

1. Implement the class code which stores the code as a vector and contains

(a) the code class declaration,

(b) a constructor that is passed values n and m and initialize the code object,

(c) a function that initializes the code randomly,

(d) a function checkCorrect which is passed a guess as a parameter, i.e. another code object, and which returns the number of correct digits in the correct location,

(e) a function checkIncorrect which is passed a guess as a parameter (i.e. another code object and returns the number of correct digits in the incorrect location. No digit in the guess or the code should be counted more than once.

2. Implement a function main() which initializes a secrete code and prints out the result of calling checkCorrect and checkIncorrect for three sample guess codes ((5, 0, 3, 2, 6), (2, 1, 2, 2, 2), (1, 3, 3, 4, 5)). Please print the secrete code as well.

The code is the following:

#include “game.h”

#include

#include

#include

#include

#include

using namespace std;

Game::Game(int y, int z)

// constructor that initalizes the secret code,length,range,

// and guesscode vector size

{

   length = y;

   range = z;

   generatecode();

   guesscode.resize(y);

}// end constructor

void Game::inputguess()

{

int tries = 1;

   cout

do

       // only allows 3 guesses by keeping track under variable tries;

       // fills the guess code vector;

       // prints how many numbers are in correct and incorrect position

       // through the function guesscodeverify

   {

       cout

       for (int i = 0; i

           cin >> guesscode[i];

       guesscodeverify(guesscode);

       tries += 1;

   } while (tries

}

void Game::generatecode()

// creates and displays the secret code

// usinr a random code generator

{

   mastercode.resize(length);

   guesscode.resize(length);

   cout

   srand((unsigned int)time(NULL));

for (int i = 0; i

   {

       mastercode[i] = rand() % range;

       cout

   }

   cout

}// end generatecode

void Game::guesscodeverify(vector temp)

// passes the guess vector to checkCorrect and checkIncorrect functions

// displays how many digits are in correct and incorrect position

{

   cout

   cout

}// end guesscodegenerator

int Game::checkCorrect(vectorguesscode)

// returns how many digits are in the correct position

{

int count = 0;

for (int i = 0; i

   {

       // compares values at same position in vector 1 by 1 and if equal increase count

       if (guesscode[i] == mastercode[i])

           count++;

   }// end for

return count;

}// end checkCorrect

int Game::checkIncorrect(vectorguesscode)

// creates temporary vectors to pass the secret and guess vector to so the original

// values are not alterd and then passes the temporary vectors and returns how many

// digits are in the incorrect position

{

int count = 0;

   vectorguesscopy = guesscode; //temporary vector

   vectormastercopy = mastercode; //temporary vetor

for (int i = 0; i

   {

       // loop for guesscopy vector digits

       for (int k = 0; k

       {

           // loop for mastercopy vector digits

           if (guesscopy[i] == mastercopy[k] && i == k && guesscopy[i] != 10)

           {

               // checks if the value in the guess vector is equal to the

               // mastercode vector value and if they are in the same position

               // and if it not equal to 10.

               // if the mastercopy and guesscopy vector value are the same

               // as well as the position then both values are replaced with

               // a 10 so that they are omitted from being included in the for

               // loop to check if the correct value is in the incorrect position

               mastercopy[k] = 10;

               guesscopy[i] = 10;

           }// end if

       }// end for(mastercopy)

   }// end for(guesscopy)

for (int i = 0; i

   {

       // loop for guesscopy vector digits

       for (int k = 0; k

       {

           // loop for mastercopy vector digits

           if (guesscopy[i] == mastercopy[k] && i != k && guesscopy[i] != 10)

           {

               // if a guesscopy vector value equal a master copy vector value

               // and the positions arent the same and the value is not equal to 10

               // then the values that match are both replaced with value 10

               // and the count is increased so that they can't be matched again

               // while going through the for loop

               count++;

               mastercopy[k] = 10;

               guesscopy[i] = 10;

           }// end if

       }//end for (mastercopy)

   }// end for (guesscopy)

return count;

}// end checkIncorrect

The header file game.h is the following:

#include

#include

#include

using namespace std;

class Game

{

public:

//   construcor & member function for

//   checkIncorrect, checkCorrect

//   and guesscode generator

   Game(int y, int z);

int checkIncorrect(vector guess);

int checkCorrect(vector guess);

void guesscodeverify(vector temp);

void inputguess();

private:

// private values and vectors

int length; // code length

int range; // range of digits

void generatecode();

   vectormastercode;

   vectorguesscode;

};// end Game class

The main function is the following:

#include

#include

#include “game.h”

using namespace std;

int main()

// includes temporary variables to passs to constructor and member functions

{

int length;

int range;

   cout

   cin >> length;

   cout

   cin >> range;

   Game game1(length, range);

// runs entire code including checkCorrect and checkIncorrect

   game1.inputguess();

return 0;

}

My Question is: Please Implement the class “response” which stores the response to a guess (number correct and number incorrect), and which includes:

(a) a constructor,

(b) functions to set and get the individual stored values within a response,

(c) an overloaded operator == that compares responses and returns true if they are equa (global),

(d) an overloaded operator

I posted the code that I have until now for your reference.

"Order a similar paper and get 15% discount on your first order with us
Use the following coupon
"GET15"

Order Now