Question
C++ program classes, default constructors, overloaded constructors, arrays of classes A Roman numeral represents an integer using letters. Examples are XVII to represent 17, MCMLIII
C++ program classes, default constructors, overloaded constructors, arrays of classes A Roman numeral represents an integer using letters. Examples are XVII to represent 17, MCMLIII for 1953, and MMMCCCIII for 3303. By contrast, ordinary numbers such as 17 or 1953 are called Arabic numerals. The following table shows the Arabic equivalent of all the single-letter Roman numerals: M 1000 X 10 D 500 V 5 C 100 I 1 L 50
When letters are strung together, the values of the letters are just added, with the following exception. When a letter of smaller value is followed by a letter of larger value, the smaller value is subtracted from the larger value. For example, IV represents 5 - 1, or 4.
MCMXCV is interpreted as M + CM + XC + V, or 1000 + (1000 - 100) + (100 - 10) + 5, which is 1995. In standard Roman numerals, no more than thee consecutive copies of the same letter are used. Following these rules, every number between 1 and 3999 can be represented as a Roman numeral made up of the following one- and two-letter combinations:
M 1000 X 10 CM 900 IX 9 D 500 V 5 CD 400 IV 4 C 100 I 1 XC 90 L 50 XL 40
1. Write a class to represent Roman numerals.
a. The class should have two constructors.: (1) A default constructor (2) A constructor that takes a string as a paramter (i.e., string representing a roman numeral) b. This class should have the following member functions, in addition to the above constructors:
(1) set - sets the member variable to the values in the function parameter (2) print - print the converted integer value (3) convert the roman number string to a positive integer (4) print the roman number string c. This class should have two PRIVATE member variables: (1) string to hold the roman numeral string (2) integer to hold the converted value
3. Create:
a. a class definition file (*.h) b. a class implementation file (*.cpp) c. a client program to test your class (*.cpp) d. a project for these code files
4. The client program should:
a. create a roman numeral object using the default constructor b. convert the roman number to the integer equivalent c. output (cout) the roman number entered and the equivalent integer value d. create a roman numeral object using the overloaded constructor e. convert the roman number to the integer equivalent f. output (cout) the roman number entered and the equivalent integer value g. create an array of the roman class of size 3 h. read, from the console, three roman numerals into the array, in a loop i. convert each array component into the equivalent integer value, in a separate loop j. output (cout) the roman number entered and the equivalent integer value for each component of the array. May be in the conversion loop. For this program, enter only valid roman numerals that convert to integers less than or equal to 3999
Test with the values MCXIV, CCCLIX, MDCLXVI
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