Sale!

Lab #5 CS-2050 – Section B

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

1 Requirements
This lab is intended to test your ability to work with structures and interface functions. You will not be
provided with a main file in your starter code, and any testing code you produce will not be graded in this
lab. In this lab, you will produce 6 interface functions (3 getters and 3 setters). All of your other required
functions must use these interface functions in order for you to receive full credit, and must not directly
access individual structs.
typedef struct {
float distance ;
unsigned int flightNumber ;
unsigned short passengers ;
} Flight ;
1.1 Getters and Setters
Info: You must write one getter and one setter function for each member of the struct type defined
in your starter code. Unlike the prelab, these functions should treat the struct pointer passed to them
as pointing to a single struct, and not a struct array.
i
1.2 printFlightArray
void printFlightArray ( Flight * flights ) ;
Info: This function takes an array of Flight structs, and prints it out with each struct on a newline,
and struct members labeled and separated by commas, like so:
Distance: 1247.91, FN: 123456, Pass: 127
Distance: 3714.07, FN: 123457, Pass: 22
i
1.3 loadFlightsFromFile
Flight * loadFlightsFromFile ( const char * filename ) ;
Info: This function will read Flight structs in from a file, and store them in a dynamically allocated
array which saves the size of the array in the pre-index location as with last lab. You are encouraged
to reuse your createArray(), freeArray() and getArraySize() functions, but is not required. The first
number in the file should be interpreted as the number of structs in the file, and the struct members
are stored in the same order as they appear in the struct definition, separated by commas. Depending
on how you write the function, this format specifier may be useful for you:
“%f, %u, %hu”
i
1
1.4 getLongestFlight
Flight * getLongestFlight ( Flight * flights ) ;
Info: This function takes an array of Flight structs, and returns a pointer to the Flight with the longest
distance.
i
1.5 getFlightByFlightNumber
Flight * getFlightByFlightNumber ( Flight * flights , unsigned int
flightNumber ) ;
Info: This function takes an array of Flight structs, and returns a pointer to the Flight with the Flight
number specified.
i
1.6 calculateAverageDistance
float calculateAverageDistance ( Flight * flights ) ;
Info: This function takes an array of Flight structs, and returns the the average distance of all flights
in the array.
i
2 Notice
Grading: Total 25 points
1. Write required getter and setter functions
* 6 points total
2. Write required print array function
* 3 points
3. Write required load from file function
* 8 points
4. Write required getLongestFlight function
* 3 points
5. Write required getFlightByFlightNumber function
* 2 points
6. Write required calculateAverageDistance function
* 3 points
!
2
Notice:
1. All of your lab submissions must compile under GCC using the −W all and −W error flags to be
considered for a grade.
2. You are expected to provide proper documentation in every lab submission, in the form of
code comments. For an example of proper lab documentation and a clear description of our
expectations, see the lab policy document.