[C] Determine data structure, abstract data type and write functions for incomplete program

timer Asked: May 2nd, 2017

Question description


Aircraft auto-pilots navigate using a flight plan. This is a collection of locations which must be flown over/to. These are called waypoints. For example flying from Hobart (international code “YMHB”) to Brisbane (“YBBN”) the plane flies over Merimbula (“YMER”) in New South Wales. In addition to a name, each waypoint also consists of a coordinate. Merimbula’s coordinate is 55H 758488 5911327. This has three parts: a grid reference (“55H”), an easting (758488), and a northing (5911327). All the waypoints from the origin (for example Hobart) to the destination (for example Brisbane) would be collected together in an ordered list with a cursor which refers to the upcoming waypoint on the journey, the origin if the plane isn’t in flight yet, or the destination if the plane has already landed. There is no restriction on the number of included waypoints on a flight path and no need to do anything other than have the cursor advance/retreat from one waypoint to the next.


Questions a to b require a brief writing justification.

a) Which underlying data structure (array or linked-list) will you use as a basis to model the flight plan? In two–three sentences, justify your answer.

b) Which kind of abstract data type (binary tree, general tree, array, stack, priority queue, double-ended queue, set, list, etc.) would you use to model the flight plan? In two– three sentences, justify your answer by indicating the functionality required.

Questions c to j require coding in the files given.

The types required to implement this include the following:

struct waypoint_int {

char name[5];

char grid[4];

long int easting;

long int northing;

}; typedef struct waypoint_int *waypoint;

You may assume the existence of the following functions which work on waypoints:

void init_waypoint(waypoint *wp, char *m, char *g, long int e, int n);

char *get_name(waypoint w);

char *get_grid(waypoint w);

long int get_easting(waypoint w);

long int get_northing(waypoint w);

void set_name(waypoint w, char *m);

void set_grid(waypoint w, char *g);

void set_easting(waypoint w, long int e);

void set_northing(waypoint w, long int n);

You may further assume the existence of the following type declarations:

struct flight_path_int;

typedef struct flight_path_int *flight_path;

c) Define the struct flight_path_int type based upon your choice in (a) and define all other required types.

d) Define a function to create the flight path stub which consists only of the origin (which is the current location) and destination. The function should have the following function header:

void init_flight_path(flight_path *fp, waypoint origin, waypoint destination);

e) Define a function to add a new waypoint to a flight path by inserting it into the list after the current location. If the given flight path is empty, an error message should be displayed and no addition should occur. Your definition should conform to the following function header:

void add_next(flight_path f, waypoint interim);

f) Define a function to search the whole list of waypoints for a particular name, printing and returning the UTM of the located waypoint as a string. Using the example from above, searching for "YMER" should show the grid, easting, and northing values and yield: "55H 5911327 758488". If the desired waypoint is not present in the list you should not print anything and return "". Your definition should conform to the following function header:

char *locate(flight_path f, char *name);

g) Write the function heading() which returns the name of the next waypoint in the list. heading() takes a Boolean variable which indicates whether the plane is required to go into a holding pattern over the current location. If this is the case — or if the plane is at the destination — then heading() should yield the name of the current location. An error message should be displayed if the flight path is empty and "" should be returned. heading() should return the name of the upcoming/current waypoint and has the following function header:

char *heading(flight_path f, bool holding);

h) Write the function remaining()that traverses the list counting the number of waypoints from the current waypoint until the named waypoint. The count should be inclusive of the waypoint. If the third parameter is true the count is forwards from the current location to the destination, if false, the count is from the current location backwards to the origin. –1 should be returned if the waypoint name cannot be found in relevant portion of the list. remaining() has the following function header:

int remaining(flight_path f, char *name, bool onwards);

i) Write the function skip() which deletes the next waypoint in the flight plan. If the flight plan is empty or if the cursor is at the destination an error message should be displayed and no change made. skip() should have the following function header:

void skip(flight_path f);

j) Sometimes in flight an issue arises and the plane needs to return to where it has come from. For this to occur the flight path must be reversed. Write the reverse() function to invert an entire flight path. reverse() has the following function header:

void reverse(flight_path f);

There are files attached, and you only need to fill out flight_path.c. Everything else is included in the files, you only need to complete the functions listed above to match your answers in a and b.

Tutor Answer

(Top Tutor) Studypool Tutor
School: Carnegie Mellon University
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors