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
Runtime Input :
305
Nepal
1300
Output :
305
Nepal
1300
1100
#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 Nepal;
Nepal.SHOWINFO();
return 0;
}
Comments
Leave a comment