Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Build an interactive C program that can manage the list of flights departing Sydney Airport. The list is stored as an array of flight_t type

Build an interactive C program that can manage the list of flights departing Sydney Airport.

The list is stored as an array of flight_t type structures

flight_t flights [MAX_NUM_FLIGHTS];

The flight_t is a structure typedef for struct flight. The struct flight contains the following fields

  • flightcode - array of MAX_FLIGHTCODE_LEN+1 chars (string)
  • departure_dt - a structure of date_time_t
  • arrival_city - array of MAX_CITYCODE_LEN+1 chars (string)
  • arrival_dt - a structure of date_time_t

Note that we now have a struct nested within a struct. The date_time_t is a structure typedef for struct date_time. The struct date_time contains the following fields,

  • month - integer between 1 and 12 (inclusive)
  • day - integer between 1 and 31 (inclusive)
  • hour - integer between 0 and 23 (inclusive)
  • minute - integer between 0 and 59 (inclusive)

Your program interacts with the nested struct array in your memory (RAM) and simple database file in your hard disk. It should provide the following features:

1. add a flight

Add a new flight to the flights through the terminal. You should collect the input by asking multiple questions from the user.

Enter flight code>

Enter departure info for the flight leaving SYD.

Enter month, date, hour and minute separated by spaces>

Enter arrival city code>

Enter arrival info.

Enter month, date, hour and minute separated by spaces>

2. display all flights to a destination

Prompt the following question

Enter arrival city code or enter * to show all destinations>

The user may enter the abbreviation of MAX_CITYCODE_LEN characters for the arrival city. The program should display all flights to the requested destination. If the user input is *, display all flights.

The display format should is as follows.

Flight Origin Destination

------ --------------- ---------------

VA1 SYD 11-26 09:54 LAX 11-26 18:26

Pay attention to the strict formatting guide:

  • Flight - left aligned, MAX_FLIGHTCODE_LEN (i.e. 6) chars at most.
  • Origin and Destination
  • City - left aligned, MAX_CITYCODE_LEN (i.e. 3) chars at most.
  • Month, day, hour, minute - two digits with leading zeros

3. save the flights to the database file

Save the flights in the hard disk as a binary/text file named database. You may use your own format to save the data. You should overwrite if database file already exists.

4. load the flights from the database file

Read the database file and put the data into flights. You may only read the data files created by your own program. You should overwrite the flights array you had in memory when loading from the file.

5. exit the program

Exit the interactive program.

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

Students also viewed these Programming questions