Question: In programming Exercise 6 in Chapter 10 , we defined a class romanType to implement Roman numbers in a program. In that exercise, we also
In programming Exercise 6 in Chapter 10, we defined a class romanType to implement Roman numbers in a program. In that exercise, we also implemented a function, romanToPositiveInteger, to convert a Roman number into its equivalent positive integer.
Modify the definition of the class romanType so that the member variables are declared as protected. Furthermore, overload the stream insertion and stream extraction operators for easy input and output. The stream insertion operator outputs the Roman number in the Roman format.
Also, include a member function, positiveIntegerToRoman, that converts a positive integer to an equivalent Roman number format. Write the definition of the member function positiveIntegerToRoman.
For simplicity, we assume that only the letter I can appear in front of another letter and that it appears only in front of the letters V and X. For example, 4 is represented as IV, 9 is represented as IX, 39 is represented as XXXIX, and 49 is represented as XXXXIX. Also, 40 will be represented as XXXX, 190 will be represented as CLXXXX, and so on.
Instructions
Derive a class extRomanType from the class romanType to do the following: In the class extRomanType, overload the arithmetic operators +, , *, and / so that arithmetic operations can be performed on Roman numbers. Also, overload the pre- and post-increment and decrement operators as member functions of the class extRomanType.
To add (subtract, multiply, or divide) Roman numbers, add (subtract, multiply, or divide, respectively) their positive integer representations and then convert the result to the Roman number format. For subtraction, if the first number is smaller than the second number, output a message saying that, Because the first number is smaller than the second, the numbers cannot be subtracted. Similarly, for division, the numerator must be larger than the denominator. Use similar conventions for the increment and decrement operators.
Write a main() to test your class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
