Question: 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
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:
The codebreaker is prompted to enter two integers: the code length n and the range of digits
m
The codemaker selects a code: a random sequence of n digits, each of which is in the range
m
The codebreaker is prompted to enter a guess, an ndigit sequence.
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 and the guess is the response would be
because one digit is the right digit in the right location, and two digits and 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
and the guess is the response is If the code is and the guess is
the response is
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 objectoriented 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 errIn the first part of the project,
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, ie 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 ie 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.
Implement a function main which initializes a secrete code and prints out the result of calling
checkCorrect and checkIncorrect for three sample guess codes
Please print the secrete code as well.
or messages if the inputs are not correct.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
