Program Assignment #2 (25 points)

advertisement
Program Assignment #2 (20 points)
Due: Monday, March 5 (4-day class)
Thursday, March 1 (2-day class)
Write a program that takes as input positive integers and converts them into their Roman
numeral system equivalents. The program should continue taking input until the user
indicates a desire to quit. The Roman numeral system uses the following symbols to represent
the numeric values listed below:
I
V
X
L
C
D
M
1
5
10
50
100
500
1000
Numbers are formed according to the following rules:
1. Only numbers greater than 0 and up to 3999 are represented (your program should check for
this).
2. As in the decimal system, the thousands, hundreds, tens and ones are expressed separately.
3. The numbers 1 – 9 are expressed as:
I
II
III
IV
V
VI
VII
VIII
IX
1
2
3
4
5
6
7
8
9
Generally, an ‘I’ preceding a ‘V’ or ‘X’ is subtracted from the second letter’s value, and you
never have more than 3 ‘I’s in a row.
4. Tens and hundreds are done the same way, except that the letters X, L, C and C, D, M are
used instead of I, V and X respectively.
A sample program run:
Hail Caesar!
Enter a number to be converted to Roman numerals, or 0 to quit:
That number is: MCMLXXVIII
Enter a number to be converted to Roman numerals, or 0 to quit:
Beware the ides of March!
Computer Science I
Sheller
cs1sp07p2 – work
1978
0
Spring 2007
Page 1
Download