Write a program to read 20 numbers from a file and convert them into roman numerals. I need a class that will hold the numbers in private data and create public functions to allow the user to print in integer and roman numeral form.
What I'm having trouble with is setting up constructors for my classes. I'll show what I have so far.
void main is something that works but is illegal. Its supported on less strict compiler settings.
why do you have an array of 20 numbers? Should number just be an integer, probably unsigned? I don't get it.
romanConvert() {} //a default constructor. you have this already (compiler makes it), but its hidden.
romanConvert(string s) {roman = s;} //something like this? ideally it would check that s is a legal roman string … maybe romanconvert can be made to return a 'invalid' result and be used here...
I put the array because I was having trouble figuring out how to input the numbers from my input file into int numbers in the class. I couldn't think of another way to do it.
ah. it looks like your class is supposed to be a single value --- akin to 'int'.
if that is the case, make a container of your class in main. OR, if you want to go with the class being a container itself, you need an array of strings to go with the array of ints, google 'parallel arrays'. but I recommend that you make the class a single value and contain it another way (this is just a better design, you will get to this later, I don't know if i can explain it fully here).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
vector<romanConvert> filevalues;
int tmp;
romanConvert rc;
while( filevar >> tmp)
{
rc.setnum(tmp);
filevalues.push_back(rc);
}
or if vectors are above you still,
romanConvert rc[20];
for(i = 0; i < 20; i++)
{
filevar >> tmp;
rc[i].setnum(tmp);
}