I wanna make sure I'm on the right track, and to have a little help! Thank you in advance.
Flight times in the United States can be estimated using a formula based on the direction of travel and
distance between airports. Regardless of the distance or direction, there is also a fixed amount of time
for the take-off and landing cycles. Needed information:
• It takes 0.2 hours for takeoff and climb-out from the origin airport.
• It takes 0.4 hours for approach and landing at the destination airport.
• The aircraft ground speed after climb-out when traveling west is 480 miles/hour.
• The aircraft ground speed after climb-out when traveling east is 540 miles/hour.
• The aircraft ground speed after climb-out when traveling north or south is 510 miles/hour.
Given this data, the flight time (FT) can be estimated as:
FT = 0.20 + 0.40 + (distance / groundSpeed);
Write a C++ program that asks the user for the distance traveled (0-6000) expressed in whole miles and
the flight direction as a character (N, S, W, E). For each flight entered output the approximate flight
time to the nearest 1/100 of an hour in a time format. Check for case and valid inputs; use constants as
needed. To pad numbers with leading zeros you need to insert a 0 into the output format-using the
setfill() manipulator.
For example: To travel from Dallas/Fort Worth to Chicago O’Hare. The distance is 801 miles and
the general direction of travel is north. The travel time can be computed as follows:
0.20 + 0.40 + (801 / 510) = 0.6 + 1.57 = 2.17 (two decimal places)
Finally, convert decimal answer to time. Format (HH:MM:SS):
2.17 = 02:10:12
Output should look similar to below.
Sample Runs:
Enter the distance traveled: 1883
Enter the direction: E
The estimated flight time is: 4.09 or 04:05:24
Enter the distance traveled: 1100
Enter the direction: S
The estimated flight time is: 2.76 or 02:45:36
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
|
#include <iostream>
using namespace std;
int main()
{
int miles;
char FlightDirection;
double FlightTime = 0;
double hours, minutes, seconds;
double decMinutes;
int groundSpeed;
cout << "Enter the distance traveled: "; cin >> miles;
cout << "Enter the direction: "; cin >> FlightDirection;
if (FlightDirection == W)
{
groundSpeed = 480;
}
else if (FlightDirection == E)
{
groundSpeed = 540;
}
else
{
groundSpeed = 510;
}
FlightTime = 0.20 + 0.40 + (miles / groundSpeed);
hours = floor(FlightTime);
decMinutes = ((ceil(FlightTime / .01) / 100) - hours) * 60;
minutes = floor(decMinutes);
seconds = (decMinutes - minutes) * 60.0;
cout << "The estimated flight time is :";
cout << decMinutes << " or ";
cout << hours << ":" << minutes << ":" << seconds << endl;
cin.get();
return 0;
}
|