Of course, you will have to make sure the computer helps the player along a bit. After the player inputs a guess, the computer should analyze it and tell the player (a) how many of his or her guessed digits were correct, but in the wrong place, and (b) how many of the guessed digits were correct and in the right place. This can be done by using functions that compare the guess with the actual array of integers, looking for matches.
Remember the minimum requirement is two functions other than main. Each function should perform a single task.
Sample Run:
Welcome to Mastermind
Please enter your four numerical guesses (space separated): 2 4 3 1
You have 2 correct number and 1 correct location.
Please enter your four numerical guesses (space separated): 4 5 3 2
Correct!
You are a MasterMind!
Hint:
When you are comparing the actual numbers to the user’s guesses, it may be easiest to use a copy of the array containing the user’s guesses. Then, each time you find a match (either exact or in the wrong location), change that guess to a –1. This way, you won’t end up counting a single guess more than once.
Lab 16
Extra Additives
Objective:
To reinforce skills in defining and manipulating arrays,with the vector class.
Computers store decimal numbers in binary form to conserve memory. Even though this allows a greater range of values, the largest integer value in many systems is 32,767 and long integers, the largest value is less than 2.2 billion.
Your task is to write a program, using a minimum of three functions that input pairs of numbers between 0 and 100 billion, inclusive. You should then add these numbers together and print the results.
Input:
The input will only consist of digit characters (‘0’ . . ‘9’). No commas or other punctuation will be in the data. All values will be non-negative. Since the integers may exceed any binary integer value allowed in the system, we shall read in the values as a string and convert each integer character to its corresponding integer digit and store it in an integer array.
Output:
Your program should print out the results of the addition. Do not print any leading zeros before any answer. Put a loop in your program to run it four times.
Examples:
Input:
Output:
124235
7453
325235
0
23523
100000000000
326346124
76434124235
The sum is: 131688
The sum is: 325235
The sum is: 100000023523
The sum is: 76760470359
Use the declarations at right to store your digits.
vector<int> largeInt1 (12,0); // initialize to zero
vector<int> largeInt2 (12,0); // initialize to zero
vector<int> finalInt (13,0); // initialize to zero
To convert digit characters to digit integers you may use this function.
int asciiToInt (char ch)
{
return (ch – ‘0’);
}
0 comments:
Post a Comment