Question: In this project, you will write a complete C + + program that allows the user to play a game of Mastermind against the computer.

In this project, you will write a complete C++ 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.
Your programs should be modular and should make full use of object-oriented programming techniques. Each class should clearly separate its interface from its implementation. Use member
functions to implement all commonly used operations. Every function should be documented to
describe its function, assumptions and limitations. Each function should validate its inputs and
print error messages if the inputs are not correct
1. 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 << that prints a response (global).
2. Implement the class mastermind which handles the playing of the game, and which includes:
(a) a code object as a data member,
(b) two constructors to initialize the game: one constructor is passed values of n and m that
were read from the keyboard, and the other constructor is passed no parameters and
uses default values for n =5 and m =10,
(c) a function that prints the secret code,
(d) a function humanGuess() that reads a guess from the keyboard and returns a code object
that represents the guess,
(e) a function getResponse() that is passed one code (a guess code), and returns a response,
(f) a function isSolved() that is passed a response and returns true if the response indicates
that the board has been solved.
(g) a function playGame() that initializes a random code, prints it to the screen, and then
iteratively gets a guess from the user and prints the response until either the codemaker
or the codebreaker has won.
3. Implement a function main() which initializes a mastermind object and then calls playGame().
The version of the code you submit should print the secret code to the screen to help us test
your code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!