Solved

problem with class and string

Posted on 2011-09-13
3
229 Views
Last Modified: 2012-05-12
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
Comment
Question by:pgmerLA
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 36532990
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
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 36533000
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
 

Author Closing Comment

by:pgmerLA
ID: 36533207
Thanks a lot!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question