Okay, I'm working on an assignment that is supposed to accept input as roman numerals and convert it to decimal form. I'm supposed to create it as a class and implementation and main files. Here are the errors I'm getting(bear in mind, none of the errors are in the Imp code):
4 Q:\USB Files\USB Files\Spring 2014\C++ Homework\Session 4\main.cpp In file included from main.cpp
4 Q:\USB Files\USB Files\Spring 2014\C++ Homework\Session 4\romanType.h variable or field `verifyInput' declared void
4 Q:\USB Files\USB Files\Spring 2014\C++ Homework\Session 4\romanType.h expected `;' before '(' token
Q:\USB Files\USB Files\Spring 2014\C++ Homework\Session 4\main.cpp In function `int main()':
19 Q:\USB Files\USB Files\Spring 2014\C++ Homework\Session 4\main.cpp `verifyInput' is not a member of `romanType'
21 Q:\USB Files\USB Files\Spring 2014\C++ Homework\Session 4\main.cpp `convertDecimal' is not a member of `romanType'
Q:\USB Files\USB Files\Spring 2014\C++ Homework\Session 4\Makefile.win [Build Error] [main.o] Error 1
Here is my main code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <cstdlib>
#include <iostream>
#include <string>
#include "romanType.h"
using namespace std;
int main()
{
string roman;
cout << "please enter a roman numeral character(s)" ;
cin >> roman;
romanType::verifyInput(roman);
cout << "Decimal of " << roman << " is " << romanType::convertDecimal(roman);
return 0;
system("PAUSE");
}
|
Here is my .h code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class romanType
{
public:
void verifyInput(string)
void convertDecimal(string)
void printDecimal() const
private:
string romanNumeral;
int decimal;
};
|
And here is my Imp code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include <string>
#include <iostream>
#include "romanType.h"
using namespace std;
void romanType::verifyInput(string roman)
{
romanNumeral = roman;
romanNumeral.toupper;
int length = romanNumeral.length();
for (int count = 0; count < length; count++)
string sub = romanNumeral.substr(count, count);
if (sub != "I" || sub != "V" || sub != "X" || sub != "L" || sub != "C" || sub != "D" || sub != "M")
cout << "Error. Invalid input"<< endl;
}
void romanType::convertToDecimal(string roman)
{
for (int i = 0; i < roman.length(); i++ )
switch (roman[i])
{
case 'M': decimal += M; break;
case 'D':
if(i + 1 != roman.size() &&roman[i+1] == 'M')
decimal -= D;
else
decimal += D; break;
case 'C':
if (i + 1 != roman.size() && roman[i+1] == 'M' || roman[i+1] == 'D')
decimal -= C;
else
decimal += C; break;
case 'L':
if (i + 1 != roman.size() && roman[i+1] == 'M' || roman[i+1] == 'D' || roman[i+1] == 'C')
decimal -= L; break;
else
decimal += L; break;
case 'X':
if (i + 1 != roman.size() && roman[i+1] == 'M' || roman[i+1] == 'D' || roman[i+1] == 'C') || roman[i+1] == 'L')
decimal -= X; break;
else
decimal += X; break;
case 'V':
if (i + 1 != roman.size() && roman[i+1] == 'M' || roman[i+1] == 'D' || roman[i+1] == 'C') || roman[i+1] == 'L') || roman[i+1] == 'X')
decimal -= V; break;
else
decimal += V; break;
case 'I':
if ( i + 1 != roman.size() && roman[i + 1] != 'I')
decimal-=1;
else
decimal+=1;
}
void romanType::printDecimal()
{
cout << "Your roman numeral is converted to " << decimal;
}
|
Thanks for any help! I did steal (borrow?) some code off of another post on here :)