Question: In C++ Part 1: Implement the game Bulls and Cows. The program uses a vector of five different digits in the range 0 to 9,

In C++

Part 1: Implement the game Bulls and Cows. The program uses a vector of five different digits in the range 0 to 9, e.g. 12345, but not 11346, called a secret number, and it is the users task to discover this number by repeated guesses. Say the number to be guessed is 67895 and the user guesses 71245; the response should be 1 cow and 1 bull because the user got one digit (7) right but in the wrong position and one digit (5) correct in the right position. The guessing continues until the user gets five bulls and wins, that is, has five digits correct and in the right positions. Print out the number of tries after winning. For the grading purposes add an option that displays the secret number if asked. Also, the secret number should be hard-coded (fixed) in the program. Your program should use at least two exceptions: Invalid_number_of_digits and Duplicated_digits, and possibly Invalid_input.

part 2: Make the previous version more general where the user can play repeatedly without stopping and restarting the program. Each game will have a new set of five digits. You can get five random digits by calling the random number generator randint(10) from std_lib_facilities.h five times. You will note that if you run that program repeatedly, it will pick the same sequence of five digits each time you start the program. To avoid that, call srand(time(0)) at the beginning of your program (before calling randint(10)). It will give different sequences of random numbers.

You need to include these header files: #include // For time() #include // For srand() and rand()

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!