Requirement
A grade school teacher wants to develop a program to generate values to a series of numbers in different base systems. The teacher is limiting the bases to be between 2 and 9, inclusive. Each line of input will have a base value and a sequence of characters representing a nonnegative number in that base. However, each number (sequence of characters) has been placed “backwards”. That is the rightmost digit is first in the sequence, the second digit from the right is encountered next, and so on.
The program reads the digits one a time. As each digit is read, the program should translate that digit into its corresponding decimal value, and then multiply it by the appropriate power of the base. There is an arbitrary number of blanks between the base and the first digit in the sequence.
Suppose that the teacher wants the students to convert the binary number 1011.
The first number, 2, represents the base. Base 2 is designated as binary. The 1101 represents a character sequence of binary digits of the number to convert. IT IS BACKWARDS! This means that the first 1 is in the one’s position or 2 to the 0 power. The second 1 is in the two’s position or 2 to the 1 power. The 0 is in the four’s position or 2 to the second power. And lastly, the rightmost 1 is in the eight’s position or 2 to the third power. Remember the number that was to be converted was 1011.
The value of this number is 1 1 + 1 2 + 0 4 + 1 8 which equals 11. Please see the sample output on how values are to be displayed.
Ask your instructor to give another example in a different base.
However, the teacher’s grade school students have entered the data values. This data CANNOT be trusted as being valid data.
Your program needs to check for valid bases and if the base is invalid write out a message that says,
Invalid base given, throwing away the rest of the line.
To throw away a line of input use cin.ignore( ). Your instructor will talk about this in class. In addition, your program needs to check for valid digits in the given base. For example, if the base is 2, any digit equal to 2 or higher is NOT legitimate. Your error message should say (i.e. input line is : 2 234510)
For the given base 2, the number is NOT valid!
You will need to throw away the rest of the line here as well.
Lastly, your program is supposed to add up the values of all valid numbers given and print this value as the final part of the output. If there are NO valid inputted numbers given, then the sum is zero (0).
Again, please see the sample output on how values are to be displayed.
The following additional requirements must be followed:
A
Your main function should adhere to the following pseudocode:
B
The above pseudocode suggests some functions. Keep these functions single-minded, performing a focused task that can be well-named. You should design pseudocode for each of these functions. All function bodies, including the body of main, should be NO more than 30 lines long, including braces, blank lines and comments.
C
You must NOT use arrays. You will lose ALL points if you do.
D
You must follow the programming standards.
E
You must follow the formatting of the sample I/O below.
F
You must thoroughly test your program.
G
You must use the following functions and you MUST add the documentation for the parameters for functions that have parameters.
H
To get credit for the request, your solution must minimally work on Test Case # 1 below.
Sample I/O
Below are two sample runs.
They do NOT cover all cases.