Please help me out. Use C++ programming language. Please do it from scratch, I a
ID: 3840549 • Letter: P
Question
Please help me out. Use C++ programming language. Please do it from scratch, I also need output too. The earlier answer has not been valid. So please make sure to explain your codes also.
Please Do not do if you are not sure. Before you post please check the question and answer one more time. Because I had bad experience earlier. thank you.
Maximum number of files: 2
Given two classes: Plane and Boat that share common methods (add,remove) of adding and removing passengers, and the following characteristics that are distinct to each object:
each has their own method to steer; Bank, Tack
each has their own medium used for travel: Air, Sea
each with their own method to accelerate: jetThrust, setSails
each with their own method to brake: wingFlap, furlSails
each has their own sense of direction:
Plane: Nose, Tail, Left, Right
Boat: Bow, Stern, Port, Starboard
Create an abstract class Vehicle that has the methods common to all classes.
Create a derived class Boat that inherits from Vehicle and has the appropriate fields and functions.
Create a derived class BoatPlane that inherits from Boat that adds the appropriate fields and overloads the appropriate functions. A BoatPlane should be able to distinguish whether it is traveling as a Plane or a Boat.
The test of your BoatPlane class should invoke the functions to accelerate, steer, brake, and stop. Each function should simply print out a label of which method is being used: for example when you have a Boat object, accelerate() should print "setSails". When you have a PlaneBoat object accelerate() should print "jetThrust"
Explanation / Answer
//Vehicle.h
#include<iostream>
#include<string>
using namespace std;
struct info
{
string steer;
string medium;
string accelerate;
string brake;
string direction;
};
class Vehicle
{
struct info Info;
public:
Vehicle();
Vehicle(string s1, string s2, string s3, string s4, string s5);
virtual void steer();
virtual void medium();
virtual void accelerate();
virtual void brake();
virtual void direction();
struct info getInfo();
};
class Boat : public Vehicle
{
public:
Boat();
Boat(string s1, string s2, string s3, string s4, string s5);
void steer();
void medium();
void accelerate();
void brake();
void direction();
};
class Plane : public Vehicle
{
public:
Plane();
Plane(string s1, string s2, string s3, string s4, string s5);
void steer();
void medium();
void accelerate();
void brake();
void direction();
};
------------------------
//Vehicle.cpp
#include"Vehicle.h"
Vehicle::Vehicle()
{
Info.steer = "";
Info.brake = "";
Info.direction = "";
Info.medium = "";
Info.steer = "";
}
Vehicle::Vehicle(string s1, string s2, string s3, string s4, string s5)
{
Info.accelerate = s1;
Info.brake = s2;
Info.direction = s3;
Info.medium = s4;
Info.steer = s5;
}
void Vehicle::accelerate()
{
cout << "In vehicle function " << Info.accelerate<<endl;
}
void Vehicle::brake()
{
cout << "In vehicle function " << Info.brake << endl;
}
void Vehicle::direction()
{
cout << "In vehicle function " << Info.direction << endl;
}
void Vehicle::medium()
{
cout << "In vehicle function " << Info.medium << endl;
}
void Vehicle::steer()
{
cout << "In vehicle function " << Info.steer << endl;
}
struct info Vehicle::getInfo()
{
struct info tmp;
tmp.accelerate = Info.accelerate;
tmp.brake = Info.brake;
tmp.direction = Info.direction;
tmp.medium = Info.medium;
tmp.steer = Info.steer;
return tmp;
}
Plane::Plane()
{
Vehicle();
}
Plane::Plane(string s1, string s2, string s3, string s4, string s5) : Vehicle(s1, s2, s3, s4, s5)
{
}
void Plane::accelerate()
{
cout << "In Plane method : " << getInfo().accelerate << endl;
}
void Plane::brake()
{
cout << "In plane method : " << getInfo().brake << endl;
}
void Plane::direction()
{
cout << "In plane method : " << getInfo().direction << endl;
}
void Plane::medium()
{
cout << "In Plane method : " << getInfo().medium << endl;
}
void Plane::steer()
{
cout << "In Plane method : " << getInfo().steer << endl;
}
Boat::Boat()
{
Vehicle();
}
Boat::Boat(string s1, string s2, string s3, string s4, string s5) :Vehicle(s1, s2, s3, s4, s5)
{
}
void Boat::accelerate()
{
cout << "In Boat method : " << getInfo().accelerate << endl;
}
void Boat::brake()
{
cout << "In Boat Method : " << getInfo().brake << endl;
}
void Boat::direction()
{
cout << "In Boat method : " << getInfo().direction << endl;
}
void Boat::medium()
{
cout << "In Boat method : " << getInfo().medium << endl;
}
void Boat::steer()
{
cout << "In Boat method : " << getInfo().steer << endl;
}
-----------------------------------------
//main.cpp
#include"Vehicle.h"
int main()
{
Vehicle *boat, *plane;
boat = new Boat("setSails", "furlSails", "Bow", "Sea", "Bank");
plane = new Plane("jetThrust", "wingFlap", "Tail", "Air", "Tack");
boat->accelerate();
plane->accelerate();
}
------------------------------------------------------------------------------------------
//output
In Boat method : setSails
In Plane method : jetThrust