Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Classes


  • Please log in to reply

#1
goldfish04

goldfish04

    Member

  • Member
  • PipPip
  • 11 posts
Well I got this far. I just need a little guidance to see where I am going. My objective is commented at the end.


#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;
b.rowing(2);
b2.rowing(5);
}


boat::boat()
{
length = 10;
width = depth = 5;
oars = 2;
}
boat2::boat()
{
length = 25;
width = 6;
depth = 3;
oars = 8;
}
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;
}
void boat2::rowing(double s)
{
rowing = true;
cout << "The boat's rowing speed is " << s << " knots." << endl;
}

void boat2::display()
{
cout << "This boat is " << length << " long and "
<< width << " wide and " << depth << " deep with "
<< oars << " oars." << endl;
}
/*

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:

*/
  • 0

Advertisements


#2
gust0208

gust0208

    Member

  • Member
  • PipPipPip
  • 311 posts
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:


  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP