Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design Flowcharts for entire programs are not always useful. However, creating a flowchart for a portion of a program can be helpful. Draw a flowchart

Design

Flowcharts for entire programs are not always useful. However, creating a flowchart for a portion of a program can be helpful.

Draw a flowchart for how you will determine the number of bulls and cows.

Draw a flowchart of how you will output a code where each digit is held in a list (e.g. a vector).

Program

This homework will be done over two weeks. Bulls and Cows is a guessing game where you try to guess a 'n' digit code. (Note: Each number in the code must be distinct.) When a number is guessed and a digit is in the correct location, then that is a bull. When a digit is in the number, but in the incorrect location, then that is a cow. So if a four digit code is 2894, and the user guesses 4698. Then that is "1 bull and 2 cows" because '9' is in the correct location and '4' and '8' are in the code but are currently in the wrong location. The guessing continues until the code is guessed in the correct order... "4 bulls"!

This website will give you a feel for the game.http://www.mathsisfun.com/games/bulls-and-cows.html

To emulate our version, click on "Options" and select any 0-9 choice.

Requirements

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

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. (You already did this last week.)

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.

Match the output of the sample runs.

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

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

Follow formatting as demonstrated in the "Sample Runs" below.

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions