RomanType to implement Roman numerals in a program

computer science

Description

a. In Programming Exercise 1 in Chapter 1, we defined a class

romanType to implement Roman numerals in a program. In that exercise, we also implemented a function, romanToDecimal, to convert a Roman numeral into its equivalent decimal number. Modify the definition of the class romanType so that the data members are declared as protected. Use the class string to manipulate the strings. Furthermore, overload the stream insertion and stream extraction operators for easy input and output. The stream insertion operator outputs the Roman numeral in the Roman format. Also, include a member function, decimalToRoman, that converts the decimal number (the decimal number must be a positive integer) to an equivalent Roman numeral format. Write the definition of the member function decimalToRoman.

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. 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 numerals. Also, overload the pre- and postincrement and decrement operators as member functions of the class extRomanType. To add (subtract, multiply, or divide) Roman numerals, add (subtract, multiply, or divide, respectively) their decimal representations and then convert the result to the Roman numeral 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 conven

tions for the increment and decrement operators. C. Write the definitions of the functions to overload the operators

described in part b. d. Write a program to test your class extRomanType.



Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.