Solved

problem with class and string

Posted on 2011-09-13
3
224 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks a lot!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  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 …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now