Bulls
and Cows
Bulls and Cows is a guessing game where you try to guess an '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 3 digit code is 289, and the user guesses 829. Then that is "1 bull and 2 cows" because '9' is in the correct location and '2' 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... "3 bulls"!
This website will give you a feel for the game. To emulate our version using 3 digits, click on "Options" and select any 0-9, 3 Codes. http://www.mathsisfun.com/games/bulls-and-cows.htmlNote:
Programming Project should be done primarily on your own. However,
it is appropriate to get some
support from your professor, and even other students. Refer to the
Syllabus for
guidelines. Remember to use Piazza and post your partial code if you
are stuck
with a problem in your code.
Use appropriate
functions to separate basic functionality of the implementation. For
example:
getCode()
, getGuess()
,
checkBulls()
, checkCows()
etc.
int
i = (rand() % 10)
)
to generate a number
between 0 - 9 (both inclusive) and use it as an index to retrieve one
of
following code for the user to guess. Note: Make sure to seed your
random
number generator using srand(time(0);
method
before calling random
number
generator method.
458 |
751 |
648 |
349 |
029 |
824 |
697 |
145 |
632 |
581 |
The code and guess must each be stored in a string.
Get guess as a string.
o If more digits than the number in the code, get number again.
o
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.
o
If any digits are repeated, get number again.
For example: If the user guess is 335, get the number again.
If the user enters string “quit” anytime during the play, the program should stop and display the code that the user was playing with output “Thanks for playing!”
You must allow the program to be played repeatedly without ending the program after successful run (that is getting 3 bulls).
o Typing 'y' or 'Y' or “Yes” causes program to run again. Anything else exits the program with output “Thanks for playing!”
Follow formatting as demonstrated in the "Sample Output" below.
5
Bonus Points: Generate 3 digit random number (all distinct
digits) to use in the play instead of using the 10 codes in the table
above.
Welcome to “Bulls and Cows”
Number to guess: ???
Enter guess: 89
2 bulls
0 cows
Enter guess: 29
3 bulls - 029 is Correct!
Enter 'y' to play again: Y
Number to guess: ???
Enter guess: 268
1 bulls
0 cows
Enter guess: 16984
“You can only enter 3 digits!”
Enter guess: 169
0 bulls
0 cows
Enter guess: 568
1 bulls
1 cows
Enter guess: 558
“Each digit must be different!”
Enter guess: 258
2 bulls
0 cows
Enter guess: 458
3 bulls - 458 is Correct!
Enter 'y' to play again: Y
Number to guess: ???
Enter guess: quit
Number to guess: 349
Thanks for playing! Goodbye.
Due:
December
02, 2016 by 4.00 PM. Submit
your .cpp file to Blackboard.
Total
Points = 100 + 5 Bonus Points
Palindromes
Palindromes are character sequences that read the same forward or backward (e.g. the strings "mom" or "radar" or “kayak” or “1234321”). You will write a program to determine whether a string is a character-unit palindrome.
Note:
Programming Project should be done primarily on your own. However,
it is appropriate to get some
support from your professor, and even other students. Refer to the
Syllabus for
guidelines. Remember to use Piazza and post your partial code if you
are stuck
with a problem in your code.
Enter the string to evaluate for palindrome: Kayak
Kayak is a palindrome
Do you want to try again (Y or N)? Y
Enter the string to evaluate for palindrome: evil
evil is not a palindrome
Do you want to try again (Y or N)? N
Thanks for playing!
Due:
November
02, 2016 by 4.00 PM. Submit
your .cpp file to Blackboard.
Total
Points = 100 + 5 Bonus Points