In: Electrical Engineering
In C++
Demonstrate inheritance. Create an Airplane class with the following attributes: • manufacturer : string • speed : float Create a FigherPlane class that inherits from the Airplane class and adds the following attributes: • numberOfMissiles : short
Answer :- The demonstration code is written below-
// C++ program to demonstrate implementation
// of Inheritance
#include <bits/stdc++.h>
using namespace std;
//Base class
class Airplane
{
public:
char manufacturer[30];
float speed;
};
// Sub class inheriting from Base Class(Parent)
class FighterPlane : public Airplane
{
public:
short int numberOfMissile;
};
//main function
int main()
{
FighterPlane obj1;
// An object of class FighterPlane has all data members and member functions of class Airplane
strncpy(obj1.manufacturer, "Truth or Dare", 15);
obj1.speed = 1234.45;
obj1.numberOfMissile = 20;
cout << "Manufacturer is :- " << obj1.manufacturer << endl;
cout << "Speed is :- " << obj1.speed << endl;
cout << "Number of missile is :- " << obj1.numberOfMissile << endl;
return 0;
}