1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
double computeFlightTime (double distance, double speed);
double computeFuelBurned (double flightTime, double burnRate);
double computeRemainingFuel (double fuelBurned, double initialFuel);
int main (double distance, double speed, double burnRate, double initialFuel )
{
ifstream inFile;
string inFileName, name, note;
char choice = 'y';
double flightTime, fuelBurned, fuelRemain;
double totalFlightTime;
double flightRange;
cout << fixed << showpoint << setprecision(1);
while(choice == 'y')
{
cout << "Welcome to Rob's airplane Flight Time and Fuel Burn calculator!" << endl;
cout << "What is the name of the file containing the destination airports?" << endl;
cin >> inFileName;
inFile.open(inFileName.c_str());
cout << "What is the speed of your airplane in miles per hour? ";
cin >> speed;
cout << "How many gallons of fuel does your airplane carry? ";
cin >> initialFuel;
cout << "How many gallons of fuel does your airplane burn per hour? ";
cin >> burnRate;
cout << left << setw(9) << "\nName";
cout << right << setw(13) << "Distance";
cout << right << setw(14) << " Flight Hours";
cout << right << setw(16) << " Gallon Burned";
cout << right << setw(16) << " Fuel Remaining";
cout << right << setw(10) << "Note";
cout << "\n" << endl;
cout << "--------------------------------------------------------------------------------";
flightTime = computeFlightTime(distance, speed);
fuelBurned = computeFuelBurned(flightTime, burnRate);
fuelRemain = computeRemainingFuel(fuelBurned, initialFuel);
totalFlightTime = initialFuel / burnRate;
flightRange = speed * totalFlightTime;
inFile >> name >> distance;
cout << "The total time the airplane can fly is " << totalFlightTime <<
"hours " << ", and can fly " << flightRange << "miles" << endl;
if(inFile.is_open())
{
while(!inFile.eof())
{
flightTime = computeFlightTime(distance, speed);
fuelBurned = computeFuelBurned(flightTime, burnRate);
fuelRemain = computeRemainingFuel(fuelBurned, initialFuel);
inFile >> name >> distance;
if( fuelRemain <= 0)
{
note = "Insufficient Fuel";
}
cout << left << setw(14) << name;
cout << right << setw(8) << distance;
cout << right << setw(10) << flightTime;
cout << right << setw(14) << fuelBurned;
cout << right << setw(14) << fuelRemain;
cout << right << setw(20) << note;
cout << "\n" << endl;
inFile >> name >> distance;
}
}
else cout << "Unable to open file";
cout << "Would you like to do another calculation? :";
cin >> choice;
}
inFile.clear();
inFile.seekg(0, ios::beg);
system("\nPAUSE");
return(0);
}
double computeFlightTime (double distance, double speed)
{
return (distance / speed);
}
double computeFuelBurned (double flightTime, double burnRate)
{
return (flightTime * burnRate);
}
double computeRemainingFuel (double fuelBurned, double initialFuel)
{
return (initialFuel - fuelBurned);
|