Hi,
I have been working on this program for a few days.. and I am so far gone I lost myself in my own program. I usually just start from scratch when I get frustrated but there is too much time invested into my heap to give up so I thought I would come here. My assignment is as follows:
Write a program that converts a number entered in Roman Numerals to decimal. Needs to consist of a class called romanType and an object that does the following:
Store the number as a Roman numeral
Convert and store the number into decimal form
Print the number as a Roman numeral or decimal number 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
After completion, I need to test the program with the following input: MCXIV, CCCLIX, MDCLXVI
Here's what I have so far in the source file:
Code://romanType.cpp #include <iostream> #include <iomanip> #include "romanType.h" using namespace std; int main() { romanType r; char romanNum; char choice; int decimal; int total; cout << setw(60) << "Welcome! Please follow the directions below." << endl; cout << endl; cout << "Please enter a Roman Numeral: "; cin >> romanNum; cout << endl; r.setRoman(romanNum); r.convertRoman(total); cout << "Do you want to see the [R]oman Numeral or the [D]ecimal? "; cin >> choice; cout << endl; if(choice == 'R' || choice == 'r') r.printRoman(romanNum); else if(choice == 'D' || choice == 'd') r.printDecimal(total); else cout << "That was not an invalid choice.." << endl; cout << endl; system("pause"); return 0; }//End main
Here's what I have so far in the implementation file:
Code:// romanTypeImp.cpp #include <iostream> #include "romanType.h" using namespace std; romanType::romanType() { }//End romanType Constructor romanType::romanType(char) { char romanNum; }//End romanType(string) Constructor romanType:: ~romanType() { }//End ~romanType Destructor void romanType::setRoman(char) { char romanNum; }//End getRoman int romanType::convertRoman(int& total) { int len = strlen(romanNum); int count[len]; for(int i = 0; i > len; i++) { switch(romanNum[i]) { case 'M': count[i] = 1000; break; case 'm': count[i] = 1000; break; case 'D': count[i] = 500; break; case 'd': count[i] = 500; break; case 'C': count[i] = 100; break; case 'c': count[i] = 100; break; case 'L': count[i] = 50; break; case 'l': count[i] = 50; break; case 'X': count[i] = 10; break; case 'x': count[i] = 10; break; case 'V': count[i] = 5; break; case 'v': count[i] = 5; break; case 'I': count[i] = 1; break; case 'i': count[i] = 1; break; }//End switch total = total + count[i]; }//End for total = 0; for (int i = 0; i < len-1; i++) { if(count[i] < count[i+1]) total = total - 2 * count[i]; }//End for }//End convertRoman void romanType::printRoman(char romanNum) const { cout << "Here is your number displayed in Roman Numeral form: " << romanNum << endl; }//End printRoman int romanType::printDecimal(int& total) { cout << "Here is your number displayed in Decimal form: " << total << endl; }//End printDecimal
And here's what I have so far in the header file:
Code://romanType.h using namespace std; class romanType { public: void printRoman(char) const; int printDecimal(int&); void setRoman(char); int convertRoman(int&); romanType(); romanType(char); ~romanType(); private: char romanNum[6]; int decimal; int total; };//End Class romanType
If anyone can offer any guidance, that would be much appreciated! I apologize for my code being a mess.. I got frantic and started throwing things in to see if I could get something to work and now I don't know what to keep, what to lose, and what to change.
Thanks for any help you guys can offer!


Reply With Quote

Bookmarks