Question
The Roman 1 2 IV 4 V VI 6 8 IX number system has the digits I, V, X, L, C, D, and M. I
The Roman 1 2 IV 4 V VI 6 8 IX number system has the digits I, V, X, L, C, D, and M. I 1
Numbers are formed according to the following rules: I
1. Only numbers up to 3,999 are represented.
2. As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (In other 5 words, it's a positional number system.) The numbers 1 to 9 are expressed like the table shown at the VII 7 right. As you can see, a I preceding a Vor X is subtracted from VIII the value, and you can never have more than three I's in a row.
Tens and hundreds are done the same way, except that the let- ters X, L, C, and C, D, Mare used instead of I, v, X respectively.
The to Roman() function accepts a decimal number such as 1978, and converts it to a string containing the Roman numerals "MCMLXXVIII". An invalid number(0, a negative number, or a number greater than 3,999) returns the string "OUT OF RANGE".
Do make things easier for you, I've already written a regular console program that converts integers to Roman numerals. You'll find it in the file decToRoman.txt. Notice that the program is long and complex. Decompose toRoman() using the following four functions, which will be tested separately as well.
string digit(int n, const string symbols);
string ones(int n) { return digit(n, "IVX"); }
string tens(int n) { return digit(n, "XLC"); }
string hundreds(int n) { return digit(n, "CDM"); }
Use make test to test your code, make stest or make run to run any student tests. Once your score is OK, use make submit to turn it in. If you get stuck, ask for help on Piazza, or come by my office hours (early.!!).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started