Question: Introduction In this project, you read, sort and search data from a binary file. The file contains information about airline flights over Orlando, with flight
Introduction
In this project, you read, sort and search data from a binary file. The file contains information about airline flights over Orlando, with flight numbers, origination and destination codes for each airport, and a date and time-stamp that indicating when the flight was detected.
We will complete this project across multiple modules. Each module requires you to submit a working version of your program up to that point. This will help everyone get started and keep on track and will let you complete our most complex assignment to date in manageable chunks.
The File
The data we'll be processing are contained in a file called acars.bin, attached to this module's Blackboard content folder.
Since completing the C source code statistical analysis program, you'll probably be pretty familiar with opening, closing and reading from text files those containing only ASCII characters and having a newline at the end of each record. But in this project you read from a binary file that contains both text and a binary integer timestamp, so different functions and approaches are required. (But the general idea of open, read, and close is of course the same).
If the file were purely text, then when you printed out the first few lines, it would look like this:
YV2840 KCLT KDAB Thu Jan 16 12:44:00 2014 YV2827 KCLT KSRQ Fri Jan 10 18:33:00 2014 YV2782 KCLT KSRQ Sat Feb 1 13:37:00 2014 YV2732 KCLT KSRQ Tue Jan 14 21:38:00 2014 YV2675 KCLT KSRQ Wed Dec 4 11:24:00 2013 Y49841 KMCO MMMX Tue Jul 23 14:25:00 2013 Y45981 KMCO MMMX Wed Feb 26 14:31:00 2014 Y45980 MMMX KMCO Tue Mar 25 14:49:00 2014 Y40981 KMCO MMMX Wed Mar 5 14:23:00 2014 Y40980 MMMX KMCO Sat Mar 29 12:38:00 2014 XX0671 KJFK MSLP Tue Mar 25 06:46:00 2014 XX0670 MSLP KJFK Tue Mar 25 00:35:00 2014 XJ3489 KLGA KRSW Mon Oct 21 11:25:00 2013 XE9103 KRSW KRIC Wed Jan 1 14:10:00 2014
but the file is actually a binary file, since even thought the flight number, the origin and the destination are char arrays, the time-stamp is a binary integer representing the date and time in the POSIX time format, sometimes known as an epoch time.
http://en.wikipedia.org/wiki/Unix_time
So the columns shown, corresponding to members in the struct you will define, are:
FlightNum, OriginAirportCode, DestAirportCode, Human-readable date string.
The end goal of this project, by the last module, is to read the file, store the information from each record in an array of structs, and then to produce a report of how many flights originated or terminated at each airport code by sorting the array and then looping through it.
If you are particularly or perversely, curious about how these data were acquired, then this link provides an overview of the technology:
http://www.rtl-sdr.com/rtl-sdr-radio-scanner-tutorial-receiving-airplane-data-with-acars/
It is not necessary to understand much of anything about these technological details this to complete this project, of course.
Deliverables
For this module, your tasks are these:
Declare a struct to match the format of the binary data. Call it what you like, I'm using flightRec.
Read the acars.bin file into an array of these structs, using the usual while !feof ( ) sort of loop and the fread ( ) C library function.
Print the flightRec structs in this form: flightNum,originAirport,destAirport,time-stamp. For now, you can just treat the time-stamp as an int, and you don't yet have to convert it to human-readable form (next week).
In other words, write a struct that contains the following:
A character array to hold six characters, plus a terminating NUL for the Flight Number.
A character array to hold four characters, plus a terminating NUL for the Origin Airport Code
A character array to hold four characters, plus a terminating NUL, for the Destination Airport Code
An int to hold a POSIX date/timestamp.
The order and size of each of these is important, since they must match the format in which the file is written, otherwise you'll read garbage. Such is the joy of binary input.
Open the acars.bin file for "rb" (read, binary), and use fread to read each struct. Don't forget to fclose the file, too. Output eachstruct you read in the comma-separated format described above. If you attempt to read the file using fgetc or fgets, for instance, it will appear corrupted.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
