Due to a hiccup in the universe, you wake up one morning in Venice with a really bad headache and an Android phone that gives the date as being in year 600. You decide to go into business as an accountant, but working in the Roman numeral system gives you more headaches. Since you conveniently installed Cxxdroid on your phone a week earlier (your time), you will program your converter using C++.
Roman numerals today are typically written using a subtractive notation; for example, 4 is written as IV. In the year 600, this notation was not standardized (see here for a detailed discussion) so numbers were written in a purely additive form using the chart
I | 1 |
V | 5 |
X | 10 |
L | 50 |
C | 100 |
D | 500 |
M | 1000 |
You are to build a simple Roman number calculator for addition and multiplication. It is to read pairs of Roman numbers and an operator, give the decimal equivalent of each, then write their sum or product as a Roman number.
DCCVI + LXXV 706 + 75 = 781 = DCCLXXXI C + XXIIII 100 + 24 = 124 = CXXIIII VIII * XII 8 * 12 = 96 = LXXXXVINotes:
read first roman number while not end of file read operator (a character) read second roman number compute result print corresponding equation read first roman numberThat is, you only read the operator and second number if the first was read successfully. Read Roman numbers using
std::string
, read the
operator into a char
. Note that cin >> x;
skips any whitespace (both regular spaces and newlines), so you do not have
to do anything special for the
spaces betwen the values.
roman_number
which acts like a built-in class with
operations (and/or constructors) to set the integer value to the
appropriate equivalent (using the above chart), operations to add two
numbers, and operations to return a string containing the printable roman
number. A basic starting point is given to you in the
file roman.cpp
. You can change any
element of this file you wish, including renaming classes and
attributes. You can split your code into multiple files if you want,
but a single file is adequate.
Submit your solution to esubmit as ex3roman. There is no submission to Canvas, but Canvas does give the last date you can submit this assignment for credit.