Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct NumType{
- int decimal_num;
- string roman_num;
- };
- class romanType
- {
- public:
- NumType myNum;
- romanType(string newnum){
- myNum.roman_num=newnum;
- myNum.decimal_num=convertRomantoDecimal(newnum);}
- int convertRomantoDecimal(string roman_num)
- {
- int intNum=0;
- for(int i=0;i<roman_num.length();i++)
- {
- int temp=0;
- switch (roman_num[i]){
- case 'M':
- temp=1000;break;
- case 'D':
- temp=500;break;
- case 'C':
- temp=100;break;
- case 'L':
- temp=50;break;
- case 'X':
- temp=10;break;
- case 'V':
- temp=5;break;
- case 'I':
- temp=1;break;
- default:
- cout<<"error number"<<endl;
- }
- intNum+=temp;
- }
- return intNum;
- }
- void printNum()
- {
- int choice;
- cout<<"Enter 1 for Roman Number, 2 for Decimal number"<<endl;
- cin>>choice;
- if(choice==1){cout<<myNum.roman_num<<endl;}
- else if(choice==2){cout<<myNum.decimal_num<<endl;}
- else{cout<<"Invaild input."<<endl;}
- }
- };
- int main(){
- romanType R1("MCXIV");
- romanType R2("CCCLIX");
- romanType R3("MDCLXVI");
- R1.printNum();
- R2.printNum();
- R3.printNum();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement