Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This needs to be done in C++ programming, either in XCode or visual studio. **THE OUTPUT OF THE PROGRAM MUST MATCH THE FORMATTING OF THE

This needs to be done in C++ programming, either in XCode or visual studio. **THE OUTPUT OF THE PROGRAM MUST MATCH THE FORMATTING OF THE SAMPLE RUNS GIVEN BELOW**

Bulls & Cows (Part 2)

Continuing from last week from outputting the code to be guessed,

1. Get guess as a single integer. (Not necessarily in this order.)

If more digits than the number in the code, get number again.

If not enough digits, assume the missing digits to the left are zero.

For example: For a 3 digit code, 35 is the same as 035 where zero is the first digit. For a 4 digit code, 35 is the same as 0035.

If any digits are repeated, get number again.

Extract single digits from the single integer and put in a vector for the code.

2. Output results of guess.

Bulls and cows on separate lines.

When correct number of bulls and echo the guess back. Be sure to include a leading zero if it has one. E.g. 023 and not 23.

3. Do not use functions to find something that you could do by iterating through the vector yourself. E.g. Using .find() instead of iterating through each element in the vector and looking at the item there.

Coding Requirements

1. The code and guess must each be stored in a vector of ints.

Sample Runs

1.

Enter number of digits in code (3, 4 or 5): 0 Enter code: 2894 Enter number of digits in code: 4 Number to guess: 2894 Enter guess: 5555 Each number must be different. Enter guess: 59 Each number must be different. Enter guess: 12345 You can only enter 4 digits. Enter guess: 4698 1 bulls 2 cows Enter guess: 9687 0 bulls 2 cows Enter guess: 2894 4 bulls - 2894 is Correct!

2.

Enter number of digits in code (3, 4 or 5): 0 Enter code: 29 Enter number of digits in code: 3 Number to guess: 029 Enter guess: 89 2 bulls 0 cows Enter guess: 29 3 bulls - 029 is Correct!

3.

Enter number of digits in code (3, 4 or 5): 5 Number to guess: 48502 Enter guess: 49602 3 bulls 0 cows Enter guess: 48502 5 bulls - 48502 is Correct!

*Again, the program output must match the output and the formatting of the sample runs given above*

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

Students also viewed these Databases questions