program in C++ in which you have to make a class Airplane having the three attribute name, direction and speed. The direction attribute can have four constraints including East, West, South and North. You have to make a constructor initialize all the attribute values. Assuming the direction around you, make a function that will change the direction of the airplane. If the airplane is headed towards the east and you call the direction function, it should rotate the plane to 90 degrees right and make the direction pointer south and so on. After that, you have to overload the same function that can accept the direction directly and set it according. You also have to make two member functions that can control the speed of an airplane one for increasing speed and the other for decreasing speed
you have to add a function class that will show us how many airplanes have been built. start of program “there is no airplane built yet”.
#include <iostream>
#include <string>
using namespace std;
class Airplane
{
private:
string name;
int capacity;
int speed;
public:
Airplane() // Constructor
{
name = "boeng 777";
capacity =400;
speed = 600;
}
Airplane(string nm, int spd, int cpcty) // Constructor 2
{
name = nm;
speed = spd;
capacity=cpcty;
}
void takeoff()
{
cout<<"The takeoff function is called.";
}
void land()
{
cout<<"The land function is called";
}
int showCapacity()
{
return capacity;
}
int showSpeed()
{
return speed;
}
string showName()
{
return name;
}
};
int main()
{
Airplane plane("Boeng 777",600, 400);
plane.takeoff();
cout <<"\nThe name of the plane is: "<<plane.showName();
cout <<"\nPlane has capacity of: "<<plane.showCapacity()<<" people.";
cout <<"\nThe speed of the plane is: "<<plane.showSpeed() <<" Km/h"<<endl<<endl;
cout<<"Plane 2.\n";
Airplane plane2;
plane2.takeoff();
cout <<"\nThe name of the plane is: "<<plane2.showName();
cout <<"\nPlane has capacity of: "<<plane2.showCapacity()<<" people.";
cout <<"\nThe speed of the plane is: "<<plane2.showSpeed() <<" Km/h";
}
Comments
Leave a comment