Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This builds on the program you wrote in the preceding module, so use that as a starting place for this project. In this module we:

This builds on the program you wrote in the preceding module, so use that as a starting place for this project. In this module we: Read the struct from the acars.bin file into an array. (You may use a dynamically-allocated array or a static one) Sort the array (using qsort ( )) so that it comes out in order of destination airport code, with the date and time formatted into a human-readable string.

Output the sorted array as a text file Print out each distinct destination airport code, along with a count of the number of times it occurs in the file. Use the C standard library function qsort ( ) to sort your array of structs. You will find that the sorting is key to simplifying the task of counting destination airport codes. The key to using qsort ( ) is a compare ( ) function you code that makes a decision of which of a pair of elements is greater everytime it is called. This function gets called over and over again from qsort ( ) until the array ends up in ascening order by the struct element you specify.

The C standard library provides functions for converting a POSIX time into a time struct, and subsequently into a human readable string as well. Use that to get human-readable formattting for the date-time stamp read from the binary file. Now use the C standard library qsort ( ) function to sort the array on either origin or destination airport code.

With the array sorted, write a function that takes the array as a parameter, and performs the following algorithm to count how many instances of each code exist. Set count to 0 Get a code from the array. For now, call it currCode. While you've not come to the end of the array begin Get the next code from the array. Call it nextCode If the nextCode == currCode, then add 1 to count else output code and count, set currCode to nextCode, set count to 0 end

Current code

image text in transcribed

#include typedef struct flightRecstruct { - char FlightNum [71 char OriginAirportCode [51: char DestAirportCode [51: int timeStamp L flightRec: int main ) int yes,: FILE fp; flightRec flightStruct: fp = fopen ("aca,, . bin", "CR"); while (1) { fread (&flightStruct, sizeof (flightRec), 1, fp) if (feof (fp) 0) break printf("%s ", flightStruct. FlightNum); printf ("%s ", flightStruct . OriginAirportCode); printf ("%s ", flightStruct . De3tAirportCode); printf ("%d ", flight Struct . timestamp); fclose (fp); return 0: #include typedef struct flightRecstruct { - char FlightNum [71 char OriginAirportCode [51: char DestAirportCode [51: int timeStamp L flightRec: int main ) int yes,: FILE fp; flightRec flightStruct: fp = fopen ("aca,, . bin", "CR"); while (1) { fread (&flightStruct, sizeof (flightRec), 1, fp) if (feof (fp) 0) break printf("%s ", flightStruct. FlightNum); printf ("%s ", flightStruct . OriginAirportCode); printf ("%s ", flightStruct . De3tAirportCode); printf ("%d ", flight Struct . timestamp); fclose (fp); return 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago