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

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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