• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 235
  • Last Modified:

problem with class and string

Hi, we have started doing classes in my CS class.
I keep getting a compiling error and I have no idea how to fix it.
Any help would be greatly appreciated.

romantype.h(16) : error C2146: syntax error : missing ';' before identifier 'romanNum'

Thanks.
class RomanType
{
public:
RomanType();
void GetArabicNumber();
void GetRomanNumeral();
void ConvertArabicToRoman();
void ConvertRomanToArabic();
void PrintRomanNumeral();
void PrintArabicNumeral();
~RomanType();

private:

int arabicNum;
string romanNum;
};

Open in new window

#include<iostream>
#include "RomanType.h"
#include <string>

using namespace std;

RomanType::RomanType()
{arabicNum=0;
romanNum="";
}
void RomanType::GetArabicNumber()
{cout<<"Type an arabic number and press enter: ";
cin>>arabicNum;
}

void RomanType::GetRomanNumeral()
{cou<<"Type a roman numeral and press enter: ";
cin>>romanNum;
}

void RomanType::ConvertArabicToRoman()
{int i=0;
while(arabicNum%1000>0)
	{romanNum[i]="M";
	arabicNum -=1000;
	i++;
	}
while(arabicNum%500>0)
	{romanNum[i]="D";
	arabicNum -=500;
	i++;
	}
while(arabicNum%100>0)
	{romanNum[i]="C";
	arabicNum -=100;
	i++;
	}
while(arabicNum%50>0)
	{romanNum[i]="L";
	arabicNum -=50;
	i++;
	}
while(arabicNum%10>0)
	{romanNum[i]="X";
	arabicNum -=10;
	i++;
	}while(arabicNum%5>0)
	{romanNum[i]="V";
	arabicNum -=5;
	i++;
	}
while(arabicNum%1>0)
	{romanNum[i]="I";
	arabicNum -=1;
	i++;
	}
}

void RomanType::ConvertRomanToArabic()
{
}

void RomanType::PrintRomanNumeral()
{
}

void RomanType::PrintArabicNumeral()
{
}
RomanType::~RomanType()

Open in new window

#include<iostream>
//preprocessor directive gives access to the io stream operations

#include "RomanType.h"
#include<string>


using namespace std;
//make I/0 available without calling class std

int main()
{

RomanType l;
l.GetArabicNumber;
return 0;
}

Open in new window

RomanType.cpp
0
pgmerLA
Asked:
pgmerLA
  • 2
1 Solution
 
jkrCommented:
Not bad for a first approach, and the errors are minor (see the comments):
#include<iostream>

#include <string>

using namespace std;

#include "RomanType.h" // move that one here after <string> has ben #included

RomanType::RomanType()
{arabicNum=0;
romanNum="";
}
void RomanType::GetArabicNumber()
{cout<<"Type an arabic number and press enter: ";
cin>>arabicNum;
}

void RomanType::GetRomanNumeral()
{cout<<"Type a roman numeral and press enter: "; // not 'cou'
cin>>romanNum;
}

void RomanType::ConvertArabicToRoman()
{int i=0;
while(arabicNum%1000>0)
	{romanNum[i]='M'; // use single quotes for characters
	arabicNum -=1000;
	i++;
	}
while(arabicNum%500>0)
	{romanNum[i]='D'; // use single quotes for characters
	arabicNum -=500;
	i++;
	}
while(arabicNum%100>0)
	{romanNum[i]='C'; // use single quotes for characters
	arabicNum -=100;
	i++;
	}
while(arabicNum%50>0)
	{romanNum[i]='L'; // use single quotes for characters
	arabicNum -=50;
	i++;
	}
while(arabicNum%10>0)
	{romanNum[i]='X'; // use single quotes for characters
	arabicNum -=10;
	i++;
	}while(arabicNum%5>0)
	{romanNum[i]='V'; // use single quotes for characters
	arabicNum -=5;
	i++;
	}
while(arabicNum%1>0)
	{romanNum[i]='I'; // use single quotes for characters
	arabicNum -=1;
	i++;
	}
}

void RomanType::ConvertRomanToArabic()
{
}

void RomanType::PrintRomanNumeral()
{
}

void RomanType::PrintArabicNumeral()
{
}
RomanType::~RomanType()
{
  // you need some body for a member
}

Open in new window

0
 
jkrCommented:
Ooops, missed the last part:
#include<iostream>
//preprocessor directive gives access to the io stream operations

#include<string>


using namespace std;
//make I/0 available without calling class std

#include "RomanType.h" // move that one here after <string> has ben #included


int main()
{

RomanType l;
l.GetArabicNumber(); // a function call needs parentheses
return 0;
}

Open in new window

0
 
pgmerLAAuthor Commented:
Thanks a lot!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now