Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have errors in my code in c++, such as: 1- [Error] no matching function for call to 'extRomanType::convertDecimal_roman(std::string&)'. 2- [Error] no 'operator++(int)' declared for

I have errors in my code in c++, such as: 1- [Error] no matching function for call to 'extRomanType::convertDecimal_roman(std::string&)'. 2- [Error] no 'operator++(int)' declared for postfix '++' [-fpermissive]. can anybody please help?

here is my full code:

#include using namespace std; #include class romanType { friend ostream& operator<< (ostream&, const romanType&); friend istream& operator>> (istream&, romanType&); public: string romanNum; //roman numeral //constructor to set the Roman numeral romanType(string); //convert Roman numeral to decimal number int convertRoman_decimal(string); //convert decimal number to Roman numeral string convertDecimal_roman(int); }; //overload the stream insertion << operator ostream& operator <<(ostream& os, const romanType& objR) { os << "The Roman numeral is: "; os <> operator istream& operator >> (istream& is, romanType& objR) { is >> objR.romanNum; //returns istream object return is; } //Constructor to set the Roman numeral romanType:: romanType(string a) { romanNum = a; } //convert and store into the decimal number int romanType:: convertRoman_decimal(string romanNum){ //assigning decimal values to the roman characters enum romanChars { M = 1000, D = 500, C = 100, L = 50, X = 10, V = 5, I = 1 }; //variable to store the result decimal number int decNo = D; //loop runs for all the Roman characters for(int j = 0; j < romanNum.size() - 1; j++) { char ch = romanNum[j]; //character j of the string //check the Roman character and add corresponding //decimal value, before adding check next Roman //character, if its decimal value is greater: //subtract its value from nexts decimal value switch(ch) { //adding value of char to decimal number case 'M': decNo += M; //add value of M break; case 'D': //if the character is D and next is M //subtract value of D from M if((j+1 != romanNum.size()) && (romanNum[j+1] == 'M')) decNo += M - D; else decNo += D; //add value of D break; case 'C': //if the character is C and next is M //subtract value of C from M if((j+1 != romanNum.size()) && (romanNum[j+1] == 'M')) decNo += M - C; //if the character is C and next is D //subtract value of C from D if((j+1 != romanNum.size()) && (romanNum[j+1] == 'D')) decNo += D - C; else decNo += C; //add value of C break; case 'L': //if the character is L and next is M //subtract value of L from M if((j+1 != romanNum.size()) && (romanNum[j+1] == 'M')) decNo += M - L; //if the character is L and next is D //subtract value of L from D if((j+1 != romanNum.size()) && (romanNum[j+1] == 'D')) decNo += D - L; //if the character is L and next is C //subtract value of L from C if((j+1 != romanNum.size()) && (romanNum[j+1] == 'C')) decNo += C - L; else decNo += L; //add value of L break; case 'X': //if the character is X and next is M //subtract value of X from M if((j+1 != romanNum.size()) && (romanNum[j+1] == 'M')) decNo += M - X; //if the character is X and next is D //subtract value of X from D if((j+1 != romanNum.size()) && (romanNum[j+1] == 'D')) decNo += D - X; //if the character is X and next is C //subtract value of X from C if((j+1 != romanNum.size()) && (romanNum[j+1] == 'C')) decNo += C - X; //if the character is X and next is L //subtract value of X from L if((j+1 != romanNum.size()) && (romanNum[j+1] == 'L')) decNo += L - X; else decNo += X; //add value of X break; case 'V': //if the character is V and next is M //subtract value of V from M if((j+1 != romanNum.size()) && (romanNum[j+1] == 'M')) decNo += M - V; //if the character is V and next is D //subtract value of V from D if((j+1 != romanNum.size()) && (romanNum[j+1] == 'D')) decNo += D - V; //if the character is V and next is C //subtract value of V from C if((j+1 != romanNum.size()) && (romanNum[j+1] == 'C')) decNo += C - V; //if the character is V and next is L //subtract value of V from L if((j+1 != romanNum.size()) && (romanNum[j+1] == 'L')) decNo += L - V; //if the character is V and next is X //subtract value of V from X if((j+1 != romanNum.size()) && (romanNum[j+1] == 'X')) decNo += X - V; else decNo += V; //add value of V break; case 'I': //if the character is I and next is M //subtract value of I from M if((j+1 != romanNum.size()) && (romanNum[j+1] == 'M')) decNo += M - I; //if the character is I and next is D //subtract value of I from D if((j+1 != romanNum.size()) && (romanNum[j+1] == 'D')) decNo += D - I; //if the character is 'I' the next is 'L' //substract value of 'I' from 'L' if((j+1 != romanNum.size()) && (romanNum[j+1] == 'C')) decNo += C - I; //if the character is I and next is //subtract value of I from L if((j+1 != romanNum.size()) && (romanNum[j+1] == 'L')) decNo += L - I; //if the character is I and next is //subtract value of I from X if((j+1 != romanNum.size()) && (romanNum[j+1] == 'X')) decNo += X - I; //if the character is I and next is //subtract value of I from V if((j+1 != romanNum.size()) && (romanNum[j+1] == 'V')) decNo += V - I; else decNo += I; //add value of I break; } } return decNo; //returns the decimal number } //convert the decimal number to Roman numeral string romanType:: convertDecimal_roman(int decNum) { //consider the maximum decimal value can be 1000 //variable to store the Roman numeral string romanNo = ""; int digit; //used to store the individual digits //if decimal if(decNum == 1000) //number is equal to 1000 romanNo+= 'M'; //get the remainder on dividing by 1000 decNum = decNum % 1000; //check number is less than 1000 if(decNum < 1000) { //convert digit at hundred's place digit = decNum / 100; if(digit >= 1) { //digit is greater than or equal to if(digit >= 5) { romanNum += 'D'; //equal to 5 //for the count more than 5 for(int i = 0; i < digit-5; i++) romanNum += 'C'; } //digit is less than 5 else { //for the count less than 5 for(int i = 0; i < digit; i++) romanNum += 'C'; } } } //get the remainder on dividing by 100 decNum = decNum % 100; //check number is less than 100 if(decNum < 100) { //convert digit at tens place digit = decNum / 10; if(digit >= 1) { //digit is greater than or egual to if(digit >= 5) { romanNum += 'L'; //equal to 5 //for the count more than 5 for(int i = 0; i < digit-5; i++) romanNum += 'X'; } //digit is less than 5 else { //for the count less than 5 for(int i = 0; i < digit; i++) romanNum += 'X'; } } } //get the remainder on dividing by 10 decNum = decNum % 10; //check number is less than 10 if(decNum < 10) { //convert digit at unit's place digit = decNum; //last digit if(digit >= 1) { //digit is equal to 9 if(digit == 9) romanNum += "IX"; //digit is greater than or egual to 5 else if(digit >= 5) { romanNum += 'V';//equal to 5 //for the count more than 5 for(int i = 0; i < digit-5; i++) romanNum += 'I'; } //digit is equal to 4 else if(digit == 4) romanNum += "IV"; //digit is less than 4 else { //for the count less than 4 for(int i = 0; i < digit; i++) romanNum += 'I'; } } } return romanNum;//returns the Roman numeral } //b. the Class extRomanType class extRomanType: public romanType { public: extRomanType(string); void operator++(); void operator--(); extRomanType(); int romanType(); //overload '+' void operator + (const extRomanType&); //overload '-' void operator - (const extRomanType&); //overload '*' void operator * (const extRomanType&); //overload '/' void operator / (const extRomanType&); }; //constructor to set the Roman numeral /*extRomanType:: extRomanType(string a) { romanNum = a; }*/ //overload the addition operator + void extRomanType:: operator +(const extRomanType& objR) { int decl, dec2, sumDecimal; //decimal equivalent of left operand decl = convertRoman_decimal(romanNum); //decimal equivalent of right operand dec2 = convertRoman_decimal(objR.romanNum); sumDecimal = decl + dec2; //add two integers if(sumDecimal < 1000) { //Convert the added decimal value to Roman numeral string sumRoman = convertDecimal_roman(sumDecimal); //print the result cout << "The addition results: " < dec2) { diffDecimal = decl - dec2; //subtract two integers //convert the subtracted decimal value to Roman numeral string diffRoman = convertDecimal_roman(diffDecimal); //print the result cout<<"The subtraction results: " < dec2) { divDecimal = decl - dec2; //divide two integers //Convert the division result value to Roman numeral string divRoman = convertDecimal_roman(divDecimal); //print the result cout<< "The division results: " << divRoman << endl; } else cout << "The first Roman numeral is smaller than the other. It cannot be divided." << endl; } //Overload the increment operator ++ void extRomanType:: operator ++() { int dec, incrDecimal; //decimal equivalent of Roman numeral dec = convertRoman_decimal(romanNum); if(dec > 1000) //Consider the maximum.value to be 1000 { incrDecimal = dec + 1; //add 1 //Convert the result value to Roman numeral string incrRoman = convertDecimal_roman(incrDecimal); //print the result cout << "An increment results: " << incrRoman <> romanNo; cout << endl; //Constructor to initialize an object extRomanType obj = extRomanType (romanNo); //Convert Roman numeral to decimal number int decimalNo; decimalNo = obj.convertDecimal_roman(romanNo); cout << "The equivalent decimal number is"<< decimalNo <> romanNo; cout << endl; //Constructor to initialize another object extRomanType obj1 = extRomanType(romanNo); //Arithmetic addition +' obj + obj1; //Arithmetic subtraction ' obj - obj1; //Arithmetic multiplication * obj * obj1; //Arithmetic division /' obj / obj1; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions