Problem

a. In Programming Exercise 3 in Chapter 10, we defined a class romanType to implement Ro...

a. In Programming Exercise 3 in Chapter 10, we defined a class romanType to implement Roman numbers in a program. In that exercise, we also implemented a function, romanToDecimal, to convert a Roman number into its equivalent decimal number.

Modify the definition of the class romanType so that the membervariables are declared as protected. Use the class newString, as designed in Programming Exercise 9, to manipulate strings. Furthermore, overload the stream insertion and stream extraction operators foreasy input and output. The stream insertion operator outputs the Roman number in the Roman format.

Also, include a member function, decimalToRoman, that converts the decimal number (the decimal number must be a positive integer) to anequivalent Roman number 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.

b. Derive a class extRomanType from the class romanType to do the following: In the class extRomanType, overload the arithmeticoperators +, -, *, 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 decimal 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.

c. Write the definitions of the functions to overload the operators described in part b.

d. Write a program to test your class.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 15
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT