We had to write a program for an assignment using classes to set different information for a boat and engine class. Well I wrote the program and I thought that it was all well until my teacher told me I didn't meet some of his specifications. He said he wanted my boat class to contain two instances of my engine class and to not use inheritance. Another guideline he gave me was to write a function in boat that prints out all of boats information and all of engines information.
I thought everything was pretty easy until he told me all of this. I am really lost on writing a class inside another class and being able to set and print out all of the information, especially without being able to use inheritance. I am new to all of these also so I am pretty shaky on all of this. Here is my current code that I made before he told me how he wants it. I need to modify this to fit his guidelines:
He said he wanted my boat class to contain two instances of my engine class and to not use inheritance.
A boat isn't a special type of engine, so it wouldn't be derived from engine.
A boat has engines. Include 2 instances of an engine as data members of the boat class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class boat
{
private:
string make;
string model;
string color;
engine engine1, engine2;// now the boat has 2 engines.
public:
void setmake(string);
void setmodel(string);
void setcolor(string);
string getmake();
string getmodel();
string getcolor();
void printboat();// this could call the printengine() function for each engine.
};
After I input that engine1 and engine2 within my boat class, I am not sure how to set values to each of the things inside engine1 and engine2 (such as horsepower, fuelcapacity, etc.). If I try anything it just says it cannot be accessed since I cannot use inheritance.