Answer to Question #198253 in C++ for Navkar

Question #198253

a class FlightData in C++ with private data members as fltNum (storing flight number), fltDest (to store destination in km’s), fltDist (to store total distance), ppUnit(to store price (in float) of fuel per unit), totalCost (to store flight running cost). A member function calCost() to find out the flight running cost and store it in totalCost

Distance

Fuel Required(in Units)

Base Charges

<=500

1000

2865

more than 500 and <=1500

3000

3875

more than 1500

4000

4885

totalCost=Base Charges + (Distance*fuel required*price per unit).

Store values of base charges, fixed for every object of class using 3 integer data members having values mentioned in table above. Public members of class are, a function to allow user to enter all data members value and a function to display all flight information with total flight running cost calculated using calCost function. Create an object of class entering all details calculating and displaying flight running cost for it.

 



1
Expert's answer
2021-05-26T23:27:12-0400
#include <iostream> 
#include <string>


using namespace std;




class FlightData{
private:
	string fltNum;// (storing flight number)
	int fltDest;//(to store destination in km’s)
	int fltDist;// (to store total distance)
	float ppUnit;//to store price (in float) of fuel per unit
	float totalCost;//(to store flight running cost)
	void calCost(){
		//Distance                  Fuel Required(in Units) Base Charges
        //<=500                     1000                    2865
		//more than 500 and <=1500  3000                    3875
		//more than 1500            4000                    4885
		float baseCharges=2865;
		float fuelRequired=1000;
		fltDist=fltDest;
		if(fltDist<=500){
			baseCharges=2865;
			fuelRequired=1000;
		}else if(fltDist>500 && fltDist<=1500){
			baseCharges=3875;
			fuelRequired=3000;
		}else{
			baseCharges=4885;
			fuelRequired=4000;
		}
		//totalCost=Base Charges + (Distance*fuel required*price per unit).
		totalCost=baseCharges+((float)fltDist*(float)fuelRequired*ppUnit);
	}
public:


	void enterAllData(){
		cout<<"Enter the flight number: ";
		cin>>fltNum;
		cout<<"Enter the destination in km's: ";
		cin>>fltDest;
		cout<<"Enter the flight price of fuel per unit: ";
		cin>>ppUnit;
	}


	void displayAllFlightInformation(){
		calCost();
		cout<<"The flight number: "<<fltNum<<"\n";
		cout<<"The destination in km's: "<<fltDest<<"\n";
		cout<<"The flight price of fuel per unit: "<<ppUnit<<"\n";
		cout<<"The flight total distance: "<<fltDist<<"\n";
		cout<<"The flight total cost: "<<totalCost<<"\n";	
	}
};


int main (){
	//Create an object of class entering all details calculating and displaying flight running cost for it.
	FlightData flightData;
	flightData.enterAllData();
	flightData.displayAllFlightInformation();


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog