Workout 1) Flight Data Collectiorn A certain airline is required to report stati
ID: 3671365 • Letter: W
Question
Workout 1) Flight Data Collectiorn A certain airline is required to report statistics regarding their on-time flight performance. You've been given the following data sample consisting of the flight number, the scheduled arrival time, and the actual arrival time for a few flights. Scheduled Actual NW1735 NW1395 UA8863 NW2852 UA2740 NW1568 NW9886 DL2981 UA882 UA231 12:03 12:56 2:19 2:45 3:10 3:10 14:21 18:36 5:15 7:16 12:15 13:21 2:20 3:15 4:00 19:36 19:21 5:15 7:44 Write a C+program to record this data in a file. Specifically, write a program that will do the following: Open an output file with the filename flightData. dat and determine if the file was opened successfully. If not, provide a suitable error message and exit the program. .Prompt the user and input three strings for the flight number and the two arrival times. Include the colon character':' in the time values. Write the strings to the file. Each datum should be separated by a single space and the line should be delimited (terminated) with a newline (' ') Continue to input and write data to the file until the user inputs the sentinel string "end" (lowercase) for the flight number. Do not write the sentinel value to the file! Close the file before exiting the program Example: Enter the flight number: NW1735 Enter the scheduled/actual arrival times: 12:03 12:15 enter flight number: NW1395 enter scheduled/actual arrival times: 12:56 13:21 enter flight number UA231 enter scheduled/actual arrival times: 7:16 7:44 enter flight number: end Now test your program by entering all the flight data above. When you have finished entering the data, use aExplanation / Answer
Please find the required program below :
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main () {
ofstream myfile;
string flightNum, scheduledAT, actualAT;
myfile.open ("flightData.dat");
myfile << "Writing this to a file. ";
cout << "enter the flight number and 2 arrival times; enter time in hh:MM format only ;enter end as flight number to stop;" << endl;
cin >> flightNum ;
while (flightNum != "end"){
cin >> scheduledAT;
cin >> actualAT;
myfile << flightNum << " " << scheduledAT << " " << actualAT << endl;
cin >> flightNum ;
}
myfile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.