Hello,
I am mainly confused by your main statement and some of your "boat2" declarations. First, lets start with the main statment. It seems as if you have all the needed functions written to do the objectives listed. You just need to declare a boat2 object and have it start rowing, so the main that I would write would be:
void main()
{
boat b;
boat b2;
boat b = new boat();
boat b2 = new boat2();
b2.rowing(5);
b.rowing(2);
b.display();
b2.display();
}
I have been working mainly in Java lately, so please excuse any typos. First, you only have one class, called "boat", so the first function declarations you have are right, e.g. "boat::boat() { ... }", but then you define some functions for a class "boat2" which does not exist as far as I can tell, the first declaration like this I see is:
boat2::boat()
{
length = 25;
width = 6;
depth = 3;
oars = 8;
}
You only have one boat class, but want to have a couple of different constructors for different starting boats, e.g. boat() and boat2(). I think what you are trying to do is declare the boat2() constructor, but referred to it as a different class, class boat 2. I would re-write this function to define the boat2() constructor in the boat class, example below:
boat::boat2()
{
length = 25;
width = 6;
depth = 3;
oars = 8;
}
Now that we are referring to boat2 as just a different constructor under the boat class, you don't need two Display functions and two Rowing functions, you just need the "boat::rowing" and "boat::display" functions and can delete the "boat2::..." functions. So, the final program would look like: (also added "row = false" to the constructors)
#include <iostream>
using namespace std;
class boat {
public:
boat();//Constructor
boat2();//Constructor
boat(double,double,double,int);
boat2(double,double,double,int);
void rowing(double);
void display();
private:
double length,
width,
depth;
int oars;
bool rowing;
};
void main()
{
boat b;
boat b2;
boat b = new boat();
boat b2 = new boat2();
b2.rowing(5);
b.rowing(2);
b.display();
b2.display();
}
boat::boat()
{
length = 10;
width = depth = 5;
oars = 2;
rowing = false;
}
boat::boat2()
{
length = 25;
width = 6;
depth = 3;
oars = 8;
rowing = false;
}
boat::boat(double l,double w,double d,int o)
{
length = l;
width = w;
depth = d;
oars = o;
}
void boat::rowing(double s)
{
rowing = true;
cout << "The boat's rowing speed is " << s << " knots." << endl;
}
void boat::display()
{
cout << "This boat is " << length << " long and "
<< width << " wide and " << depth << " deep with "
<< oars << " oars." << endl;
}
Cheers,
Tom
1.declare a second boat with
length 25
width 6
depth 3
8 oars
2.write the definition for the class method
rowing.
3.have the boat go at 5 knots
4.add a class method that will print out
the dimensions of a boat
5.have the dimensions of each boat displayed
place your new sample output here: