C Programming This is my workout 1 program include include i

C++ Programming

This is my workout 1 program:

#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;
}

And this is all the data:

Flight Number Scheduled Arrival time Actual Arrival time

NW1735 12:03 12:15

NW1395 12:56 13:21

UA8863 2:19 2:20

NW2852 2:45 3:15

UA2740 3:10 4:00

NW1568 3:10 3:11

NW9886 14:21 19:36

DL2981 18:36 19:21

UA882 5:15 5:15

UA231 7:16 7:44

2) Flight Arrival Statistics (This is a longer problem. Even if you do not get it finished during the lab, do as much as you can since it involves many useful skills.) Input the data from the file you created in Workout Exercise (1) and determine the average, maximum and minimum flight delays for the flights recorded in the file. Specifically, write a C++ program that will do the following Solicit the name of a flight data file from the user and open it for reading. Determine if the file was opened successfully. If not, provide a suitable error message and exit the program Read all the records of the file and determine: The average flight delay The flight number and delay with the minimum delay The flight number and delay with the maximum delay Display all delay values using time format (hours:minutes) Your program should use the functions you created in the Stretch exercises! (elapsedTime, timeToMinutes, MinutesToTime). Program Note: The ifstream.open( filename) function will not accept a string variable as an argument without first being converted to a different form. After the user has input the filename, use the following in your program to allow a string variable as the filename in the open function: stream.open (stringvariable.cstr); where ifstream is the name of your input file stream object and stringvariable is the name of the string variable that contains the filename you wish to open. Hint: This is a longer and more complicated program than the previous ones. Before writing code, carefully outline what your program needs to do. Then write and test the program incrementally. Specifically, you might want to start by writing the portion of the program that gets the flight data file name, opens that file for reading, and counts the number of lines of flight data in it. Once you have that working add the portion for computing and displaying the average. Etc.

Solution

public int avgDelay(int x)

{

int hour,min,sec;

cout<<\"please enter arrival time(HH:MM:SS)\";

cin>>at;

cout<<\"please enter expected arrival time(HH:MM:SS);

cin>>expt;

int delay=at-expt;

Cout<<\"enter number of times delay happened:;

cin>>n;

x=(delay/n);

cout<<x;

}

int maxflightdelay(int n)

{

int delays,max[50];

cout<<\"enter the flight delay values in (HH:MM:SS);

for(i=0;i<=n;i++)

cin>>delays;

cout<<max[i];//endl

}

public int minflightdelay(int n)

{

int min[50],delay,smallest

C++ Programming This is my workout 1 program: #include <iostream> #include <string> #include <fstream> using namespace std; int main () { ofst
C++ Programming This is my workout 1 program: #include <iostream> #include <string> #include <fstream> using namespace std; int main () { ofst

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site