Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:
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 errIn the first part of the project,
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.
or messages if the inputs are not correct.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

Using 2's complement method solve (18-7)

Answered: 1 week ago