< previous page page_386 next page >

Page 386
Your program inputs two Roman numbers and an arithmetic operator and prints out the result of the operation, also as a Roman number. The values of the Roman digits are as follows:
I
1
V
5
X
10
L
50
C
100
D
500
M
1000

Thus, the number MDCCCCLXXXXVI represents 1996. The arithmetic operators that your program should recognize in the input are +, -, *, and /. These should perform the C++ operations of integer addition, subtraction, multiplication, and division.
One way of approaching this problem is to convert the Roman numbers into integers, perform the required operation, and then convert the result back into a Roman number for printing. The following might be a sample run of the program:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Enter the first number:
MCCXXVI
The first number is 1226
Enter the second number:
LXVIIII
The second number is 69
Enter the desired arithmetic operation:
+
The sum of MCCXXVI and LXVIIII is MCCLXXXXV (1295)
Your program should use proper style and indentation, appropriate comments, and meaningful identifiers. It also should check for errors in the input, such as illegal digits or arithmetic operators, and take appropriate actions when these are found. The program also may check to ensure that the numbers are in purely additive form-that is, digits are followed only by digits of the same or lower value.
6. Develop a top-down design and write a program to produce a bar chart of gourmet-popcorn production for a cooperative farm group on a farm-by-farm basis. The input to the program is a series of data sets, one per line, with each set representing the production for one farm. The output is a bar chart that identifies each farm and displays its production in pints of corn per acre.
Each data set consists of the name of a farm, followed by a comma and one or more spaces, a float number representing acres planted, one or more spaces, and an int number representing pint jars of popcorn produced.
The output is a single line for each farm, with the name of the farm starting in the first column on a line and the bar chart starting in column 30. Each mark in the bar chart represents 250 pint jars of popcorn per acre. The production goal for the year is 5000 jars per acre. A vertical bar should appear in the chart for farms with lower production, and a special mark is used for farms with production greater than or equal to 5000 jars per acre. For example, given the input file

 
< previous page page_386 next page >