?
Solved

problem with class and string

Posted on 2011-09-13
3
Medium Priority
?
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
  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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

762 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