[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

problem with class and string

Posted on 2011-09-13
3
Medium Priority
?
234 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

656 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