Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class RomanType
- {
- string romanNumerals;
- int decimalValue;
- public:
- void setNumerals(string);
- string getNumerals();
- void convertNumerals();
- void setValue(int);
- int getValue();
- void print();
- };
- void RomanType::setNumerals(string rNum)
- {
- romanNumerals = rNum;
- }
- string RomanType::getNumerals()
- {
- return romanNumerals;
- }
- void RomanType::convertNumerals()
- {
- decimalValue = 0;
- for(int i = 0; i < getNumerals().size(); i++)
- {
- switch(getNumerals()[i])
- {
- case 'M':
- RomanType::setValue(1000);
- break;
- case 'D':
- RomanType::setValue(500);
- break;
- case 'C':
- RomanType::setValue(100);
- break;
- case 'L':
- RomanType::setValue(50);
- break;
- case 'X':
- RomanType::setValue(10);
- break;
- case 'V':
- RomanType::setValue(5);
- break;
- case 'I':
- RomanType::setValue(1);
- break;
- }
- }
- }
- void RomanType::setValue(int dValue)
- {
- decimalValue += dValue;
- }
- int RomanType::getValue()
- {
- return decimalValue;
- }
- void RomanType::print()
- {
- int userDecision;
- cout << "[1] To Print Roman | [2] To Print Decimal Value: ";
- cin >> userDecision;
- switch (userDecision)
- {
- case 1:
- cout << "Roman Numerals Entered: \t" << getNumerals() << endl;
- break;
- case 2:
- cout << "Value Of Roman Numerals Entered: \t" << RomanType::getValue() << endl;
- }
- }
- int main()
- {
- string userInput;
- cout << "Enter Your Roman Numerals: " << endl;
- cin >> userInput;
- RomanType rType;
- rType.setNumerals(userInput);
- rType.convertNumerals();
- rType.print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement