What is a test scenario for bulls and cows

Assignment Help C/C++ Programming
Reference no: EM131487140 , Length: 1

Problem Set: Object-Oriented Solution Design

Bulls and Cows is an old code-breaking round-based paper and pencil game for two players, predating the commercially marketed board game Mastermind.

The game works as follows. Both players write down a 4-digit secret number. The digits must be all different. Then, in turn, the players try to guess their opponent's number who gives the number of matches. If the matching digits are on their right positions, then they are "bulls." If the numbers are on different positions, then they are "cows."

Example:
- Secret number: 4286
- Opponent's try: 1234
- Answer: 1 bull and 1 cow. (The bull is "2", the cow is "4.")

The first player to reveal the other player's secret number wins the game.

The goal of this problem set is to develop an object-oriented solution for this game in which a human player tries to guess the secret number chosen by the computer. The aim of the game becomes: use as few guesses as possible to reveal the computer's secret number.

The program consists of two parts: the class BullsAndCows and a main function. The main function defines a "game loop" that allows a player to repeatedly guess the computer's secret number. The game loop, defined in the main function, keeps the game alive as long as the flag lPlayAgain is true. In each round, the game asks the human player to guess the secret number. We use a do-while loop to allow for multiple guesses. Once the players guessed correctly, the round is over and the player has the option to continue or terminate the game.

If the player presses any character other than ‘Y' and ‘y', then the game ends. BullsAndCows lGame; bool lPlayAgain = true; while ( lPlayAgain )
{
cout << "New game" << endl; lGame.start ();
string lInput;
do
{
cout << "Make a guess: "; cin >> lInput; lGame.guess( lInput );
cout << "Number of bulls: " << lGame.getBulls()
<< ", number of cows: " << lGame.getCows() << endl;
} while ( lGame.getBulls() != 4 ); cout << "New game, Y/N? ";
cin >> lInput;
if ( lInput[0] != 'Y' )
{
lPlayAgain = lInput[0] == 'y';
}
}
cout << "Game over. Good bye." << endl;

The specification of the class BullsAndCows is given below:
SWE20004 Semester 1, 2017 Dr. Markus Lumpe 3
#include <string>
class BullsAndCows
{
private:
int fSecretNumbers[9];
int fBulls; int fCows; public: BullsAndCows(); void start();
void guess( std::string aNumberString ); int getBulls() const; // getter for bulls int getCows() const; // getter for cows
};

The class BullsAndCows defines a private array of nine integers 1 to 9. The constructor BullsAndCows() initializes this array. In particular, it uses a for-loop to set each element in the array fSecretNumbers to a unique value between 1 and 9.

The method start() shuffles the numbers in the array fSecretNumbers. We use the shuffling process developed by Fisher&Yates, shown in lecture 7, to rearrange the numbers. The value n has to be set to 9.

The method guess( std::string aNumberString ) implements the game logic. The parameter aNumberString contains the user input. It must be a 4-digit number in which all digits are different. For the purpose of this problem set, we assume that the player always provides a correct number (i.e., all digits are different). Each character in aNumberString can be easily converted into an integer value by subtracting ‘0' - the character for zero. The checking process uses a simple for-loop over the first four entries in the fSecretNumbers array. The following pseudo-code captures the required algorithm:

fBulls = 0
fCows = 0
for i = 0 to 3 do
declare int variable lTest, initialized to aNumberString[i] - ‘0'
if fSecretNumbers[i] == lTest then
lBulls = lBulls + 1;
else
for j = 0 to 3 do
if fSecretNumbers[j] == lTest then
lCows = lCows + 1; break; // terminate for loop end;
end; end; end;
In order to implement the class BullsAndCows, you need to include the cstdlib and the iostream C++ libraries. Also, you need to define two .cpp files, one for the implementation
of class BullsAndCows and one containing the main function. The program is a simple Win32 console application that does not require any command line arguments.
Test run:
Bulls and Cows, brought to you by StudentName (StudentID)

New game
Make a guess: 1234
Number of bulls: 0, number of cows: 3 Make a guess: 5678
Number of bulls: 0, number of cows: 1 Make a guess: 2813
Number of bulls: 1, number of cows: 3 Make a guess: 2381
Number of bulls: 4, number of cows: 0 New game, Y/N? n
Game over. Good bye.

Tasks

You have already been given the details regarding the requirements analysis and the design specification. To complete this problem set, you need to

1. Create and study a test scenario (on paper). What is a test scenario for Bulls and Cows? Answer: pick a 4-digit number in which all numbers are different. This number serves as the computer's secret choice. Testing the game now revolves around guessing this number. Proceed normally. That is, assume the human player's role and guess a number. Since you know the secret number, you can generate the answer of the computer (number of cows and bulls). Naturally, the answer needs to be correct. Then follow a logical inference process. That is, the test continues with drawing a logical conclusion about the closeness of the player's number to the computer's number and which steps to take to improve the guess, if the player has not yet guessed correctly. The test ends, when the player has found the correct number.

2. Implement the solution. (print program code and result from test run)

3. Annotate your solution with documentation comment tags

Your application also needs to produce a "production maker". This information must be written to the console (and be part of the program):

Bulls and Cows, brought to you by StudentName (StudentID) where StudentName is you name and StudentID is your student id.

The implementation requires approx. 80 lines of code plus the main function.

Reference no: EM131487140

Questions Cloud

Provide a basic example of how lp can be used for marketing : Discuss the requirements of a linear programming (LP) model. Discuss and provide a basic example of how LP can be used for marketing and/or consumer research.
Kohwe corporation plans to borrow : What is? Kohwe's share price today if the investment is financed with? debt?
Find an organization that has recently implemented : Find an organization that has recently implemented a new quality initiative. Discuss specifically the steps taken to implement the new process.
How would you believe you could ensure your employees : How would you (as prospective manager) believe you could ensure your employees are and/or remain engaged on the job?
What is a test scenario for bulls and cows : SWE20004 Semester 1, 2017 Dr. Markus Lumpe 2 - Create and study a test scenario (on paper). What is a test scenario for Bulls and Cows?
Analyze the primary economic assumptions : Evaluate the fundamental reasons why price and utilization economic factors in the healthcare setting influence competitive market status.
Explain how customer final approval will be received : How customer final approval will be received. Criteria to be met for the customer to agree that the project is successfully completed.
Discuss biggest challenges facing financial managers today : Find at least two articles from the Ashford University Library that highlight and discuss two of the biggest challenges facing financial managers today.
What priorities would you set for the training plan : Which department appears to be creating the most duplicates? What priorities would you set for the training plan?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Why encapsulation and inheritance make programming difficult

Why do C++ capabilities such as polymorphism, encapsulation, and inheritance make programming difficult

  Battleship redux

Game Battleship is back and better than ever. Instead of hacking everything together in C, you will instead leverage C++ and all of your newly gained object oriented programming knowledge to construct a much cleaner end product.

  Develop classes describing various types of buildings

Describe how inheritance might be used to develop classes describing various types of buildings.

  Many bank atm machines have recently added the ability to

many bank atm machines have recently added the ability to dispense cash with- drawals in multiple bill denominations

  Create two arrays with ten random numbers

Determine the largest difference (only subtract corresponding index numbers) between these two arrays. (hint: create a third array with the differences)

  Program that contains two functions in addition to main

Write a program that contains two functions in addition to main. The first one takes 2 arguments (an int array and an int) and returns nothing.

  Design an employee class

Design an Employee class that has fields for the following pieces of information: Employee Name and Employee Number

  Write c++ programs

Write a C++ program to accept distance in kilometers, coverts it to meters and then displays the result. Write a C++ program to find area and circumference of a circle.

  Explain strings are an important part of programming

Strings are an important part of programming. They are used to transfer all sorts of data between the user and program, as well as from program to program. Humans communicate with streams because they are flexible enough to encode words and vari..

  Write a program that displays a weekly payroll report

Write a program that displays a weekly payroll report

  Declare and define constructor

Declare and define constructors and Declare and define destructors - Describe what is an attribute or data member of a class

  Class mail order

Set up one one-dimensional array for each field: product number (integer), unit price (double), and current inventory level (integer) in main memory to hold the above product information. There should be five rows (0 to 4) in each array, one for e..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd