Answer to Question #173451 in C++ for praveenkumar.b

Question #173451

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


1
Expert's answer
2021-03-24T14:08:37-0400
#include <iostream>
#include <string>
using namespace std;

class Flight {
    int FlightNumber;
    string Destination;
    float Distance;
    float Fuel;
    void CALFUEL();
public:
    Flight(int num, string dest, float dist);
    void Display(ostream& os);
};

Flight::Flight(int num, string dest, float dist) :
FlightNumber(num), Destination(dest), Distance(dist) {
    CALFUEL();
}

void Flight::CALFUEL() {
    if (Distance <= 1000)
        Fuel = 500;
    else if (Distance <= 2000)
        Fuel = 1100;
    else
        Fuel = 2200;
}

void Flight::Display(ostream& os) {
    os << "Flight number " << FlightNumber << " to " 
       << Destination << " needs " << Fuel << " fuel" << endl;
}

int main() {
    Flight fl1(123, "Philadelphia", 200);
    Flight fl2(345, "Memphis", 1230);
    Flight fl3(987, "Austin", 2120);


    fl1.Display(cout);
    fl2.Display(cout);
    fl3.Display(cout);
}

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
APPROVED BY CLIENTS