C Programming Please suppose you have the file named flightD
C++ Programming
Please suppose you have the file named flightData.dat and make a program to open an outpthis file.
Thank you.
Workout 1) Flight Data Collection A certain airline is required to 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 Elight Number Arival Time Arrival Time 1735 12:03 12:56 2:19 2:45 3:10 3:10 14:21 18:36 5:15 7:16 NW1395 UA8863 NW2852 UA2740 12:15 13:21 2:20 3:15 4:00 NW 1568 NW9886 DL2981 UA882 UA231 19:36 19:21 5:15 7:44 Write a C+t program to record this data in a file. Specifically, write a program that will do the following Open an ouput file with the filename flightData.dat and determine if the file was opened Open an ouiput file with the filename flightData. dat and d 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 (Nn) Con ntinue 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! ose the file before exiting the program. Example Enter the flight number Enter the scheduled/actual arrival times: 12:03 12:15 enter flight number: Nw1395 enter flight number NW1395 enter scheduled/actuail larräval times: 12 enter scheduled/actual arrival time enteri flight number: UA2 enter scheduled/actual arTr arrival times: 7:16 7:4 number ow test your program by entering all the fli data above. When you have finished entering the data, use aSolution
#include <iostream>
 #include <string>
 #include <fstream>
 using namespace std;
int main () {
 ofstream myfile; // output stream
 string fname,stime,atime;
 myfile.open(\"flightData.dat\"); // open file
 if (!myfile.is_open()) { // check if file is open or not
 cout<< \"unable to open file\ \";
 exit(0);
 }
 myfile<< \"FlightNumber ScheduledArrivalTime ActualArrivalTime\ \";
 while(true){
 cout << \"Enter the flight Number:\";
 cin >> fname;
 if(fname.compare(\"end\")==0) // check if input is end
 break;
 cout << \"Enter the sheduled/actual arrival times:\";
 cin >> stime;
 cin >> atime;
 myfile << fname << \" \" << stime << \" \" << atime << endl; // write to file
 }
 myfile.close(); // close file
 return 0;
 }
/*sample input
Enter the flight Number:NW1735
Enter the sheduled/actual arrival times:12:03 12:15
Enter the flight Number:end
Samle output
FlightData.dat
FlightNumber ScheduledArrivalTime ActualArrivalTime
 NW1735 12:03 12:15
*/


