Write a program that converts a number entered in Roman numerals to decimal. You
ID: 3643227 • Letter: W
Question
Write a program that converts a number entered in Roman numerals to decimal. Your program should consisit of a "class", say, romanType. An object of type romanType should do the following:a. Store the number as a roman numeral.
b. Convert and store the number into decimal.
c. Print the number as a roman numeral or decimal as requested by user.
the decimal values of the roman numerals are:
M=1000, D=500, C=100, L=50, X=10, V=5, I=1.
d. Test your program using the following Roman numerals: MCXIV, CCCLIX, MDCLXVI
i need to use: int main()
and use void statement defined outside of the main
Explanation / Answer
#include
<iostream> //start of program.
#include
<cmath>
using
namespace std;
class
romanType // class
{
void roman();
int convert();
void print();
void get();
int M, D, C, L, X, V, I;
char romanNumeral;
};
void
romanType::roman()
{
M = 1000;
D = 500;
C = 100;
L = 50;
X = 10;
V = 5;
I = 1;
}
int
romanType::convert()
{
if (romanNumeral = M)
{
cout <<
"1000";
}
else if(romanNumeral = D)
{
cout <<
"500";
}
else if(romanNumeral = C)
{
cout <<
"100";
}
else if(romanNumeral = L)
{
cout <<
"50";
}
else if(romanNumeral = X)
{
cout <<
"10";
}
else if(romanNumeral = V)
{
cout <<
"5";
}
else if(romanNumeral = I)
{
cout <<
"1";
}
return romanNumeral;
}
void
romanType::print(){
cout << romanNumeral << endl;
}
void
romanType::get(){
}
int
main()
{
char romanNumeral;
cout <<
"This is the Roman numeral to decimal converter Please Roman numerals to be converted: ";
cin >> romanNumeral;
system (
"pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.