Answer to Question #198906 in C++ for anuj

Question #198906

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-27T23:08:40-0400
#include <iostream>

using namespace std;


class FlightData {
private:
    int fltNum;
    double fltDist;
    double ppUnit;
    double totalCost;
    
public:
    FlightData();
    void setNum(int num);
    void setDist(double dist);
    void setPrice(double price);
    void calCost();
    void display();
};


FlightData::FlightData() {}


void FlightData::setNum(int num) {
    fltNum = num;
}


void FlightData::setDist(double dist) {
    fltDist = dist;
}


void FlightData::setPrice(double price) {
    ppUnit = price;
}


void FlightData::calCost() {
    if (fltDist <= 500) {
        totalCost = 1000 + 2865 * fltDist * ppUnit;
    }
    else if (fltDist <= 1500) {
        totalCost = 3000 + 3875 * fltDist * ppUnit;
    }
    else {
        totalCost = 40000 + 4885 * fltDist * ppUnit;
    }
}
void FlightData::display() {
    cout << "Flight number: " << fltNum << endl
         << "Flight distance: " << fltDist << endl
         << "Total cost: " << totalCost << endl;
}


int main() {
    FlightData fd;
    fd.setNum(12345);
    fd.setDist(1200);
    fd.setPrice(2.5);
    fd.calCost();


    fd.display();
}

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