Liners 64, 68 and 72: The way you call a method is object.method(). For example, at line 64, you want to call the read() method on the rat1 object. The code for that is
rat1.read()
. Make that change and change lines 68 & 72 accordingly.
Line 76: To output the 3rd rational number (rat3), just call it's write() method. Use what I said above to figure out how to do this.
Line 85: You get the numerator by calling a rational's get_numerator() function. For example, to print the of rat3, you'd do
cout << rat3.get_numerator()
;
The comments at the top say "we have made member variable private" but I don't see the private member variables. You should add those.
Right now all of those methods must be written just to get this to compile. To help with testing, here are stubs for most methods. These compile and print "blah blah is not implemented." By implementing these one at a time, you'll be able to get the program working a little at a time.
Add this to the program.
Implement the default constructor.
Get the code to compile and then replace the "not yet implemented" message in each method with an actual implementation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
rational::rational(int numerator)
{
cout << "rational(num) not yet implemented\n";
}
rational::rational(int n, int d)
{
cout << "rational(num, denom) not yet implemented\n";
}
void rational::read()
{
cout << "read not yet implemented\n";
}
void rational::write()
{
cout << "write not yet implemented\n";
}
void rational::sum(rational rat1, rational rat2)
{
cout << "sum not yet implemented\n";
}
int rational::get_numerator()
{
cout << "get_numerator not yet implemented\n";
return 0;
}
int rational::get_denominator()
{
cout << "get_denominator not yet implemented\n";
return 1;
}
|