C++ programme
Define a class Flight with the following specifications
Private Members a data member are
Flight number of type integer A data member Destination of type string A data member Distance of type float A data member Fuel of type float A member function CALFUEL() to calculate the value of Fuel as per the following criteria
Distance Fuel
<=1000 500
more than 1000 and <=2000 1100
more than 2000 2200
Public Members
FEEDINFO() A function FEEDINFO() to allow user to enter values for Flight Number, Destination, Distance & call function CALFUEL() to calculate the quantity of Fuel. SHOWINFO() A function SHOWINFO() to allow user to view the content of all the data members.
(Implement the concept of class and objects)
#include <iostream>
#include <string>
using namespace std;
class Flight {
   int numberFlight;
   string Destination;
   float Distance;
   float Fuel;
  Â
   float CALFUEL() {
      float fuel = 0;
      if(Distance <= 1000)
        fuel = 500;
      else if (Distance > 1000 && Distance <= 2000)
        fuel = 1100;
      else Â
         fuel = 2200;
      return fuel;
   }   Â
public:
    Flight(){     // default constructor
       cout<<"Flight information:"<<endl;
      FEEDINFO () ;
    }
    // parameterized constructor
   Flight (int num, string destination, float distance){
     numberFlight = num;
     Destination = destination;
     Distance = distance;
     Fuel = CALFUEL();
   }
   ~Flight() {   } // destructor
   void FEEDINFO () {
      cout << "Enter Flight number: " ;
      cin >> numberFlight;
      cout << "Enter Destination:  " ;
      cin >> Destination;
      cout << "Enter Distance:     " ;
      cin >> Distance ;
      Fuel = CALFUEL();
      cout << "Fuel :        " << Fuel << endl;
   }
   void SHOWINFO () {
      cout<<endl;
      cout<<"_______________________________________"<<endl;
      cout << "Flight number: " << numberFlight << endl;
      cout << "Destination:  " << Destination << endl;
      cout << "Distance:     " << Distance << endl;
      cout << "Fuel :        " << Fuel << endl <<endl;         Â
      };
};
int main()
{
   // default constructor
   Flight Dubai;
   Dubai.SHOWINFO();
   // parameterized constructor  Â
   Flight Mexico(123, "Mexico", 1200);
   Mexico.SHOWINFO();  Â
   return 0;
}
Comments
Leave a comment