17.3 Programming Assignment 3: Flight Navigation System For this assignment, we are extending from Programming Assignmen

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

17.3 Programming Assignment 3: Flight Navigation System For this assignment, we are extending from Programming Assignmen

Post by answerhappygod »

17 3 Programming Assignment 3 Flight Navigation System For This Assignment We Are Extending From Programming Assignmen 1
17 3 Programming Assignment 3 Flight Navigation System For This Assignment We Are Extending From Programming Assignmen 1 (119.36 KiB) Viewed 131 times
Written in C++, templates are provided, flightpln cpp and headerfile must be completed while the other 2 files are given as atemplate.
17.3 Programming Assignment 3: Flight Navigation System For this assignment, we are extending from Programming Assignment 2 (PA2) to create a true Flight planning system that can process a list of waypoints. Firstly, in structs.h, define the Plane struct and Waypoint struct from PA2, don't forget the include guards! Important: Plane and Waypoint struct name must have the first character capitalized! Secondly, in flightplan.h, define a Flightplan class with the following members: Important: FlightPlan class name must have the F and P capitalized! (standard C++ practice is to use snake casing in class and struct names) private: • current_plane: a Plane struct that is assigned to this flight plan • waypoints: a pointer that will hold the dynamic array of waypoints num_waypoints: an int that holds the number of Waypoint that are in this flight plan . public: • A overloaded constructor that takes in a Plane struct and sets current_plane to it, num_waypoints to 0, and waypoints to nullptr • A destructor that destroys the waypoints dynamic array (if it is not already nullptr) and sets it to nullptr • A copy constructor that performs a deep copy of the waypoints dynamic array . A copy assignment operator that performs a deep copy of the waypoints dynamic array • get_current_plane is a function that returns the current_plane get_waypoint is a function that takes in an index i (int) and returns the Waypoint in waypoints at position i • set_waypoint is a function that takes in an index i (int) and a Waypoint struct and sets the Waypoint at index i in waypoints to that new Waypoint. save_waypoints is a function that takes in a string for the filename, then writes all of the Waypoint in waypoints into that file using the following format: <NUMBER OF WAYPOINTS> <HEADING> <DISTANCE> <ALTITUDE> <HEADING> <DISTANCE> <ALTITUDE> <HEADING> <DISTANCE> <ALTITUDE> ...
Here is an example waypoints.txt file: 3 100 1000 3000 100 800 4000 200 900 3500 • load_waypoints is a function that takes in a string for the filename and reads the file; it first reads num_waypoints (first line), the function then creates a new dynamic array for waypoints with the new num_waypoints, then it reads all of the Waypoint from the file into the waypoints array check_flightplan is a function that returns whether the given Plane can fly through all Waypoint in the waypoints array. It returns true or false accordingly. This function does not take any parameters because it uses the Flightplan's current_plane and waypoints! For each Waypoint in the waypoints array: 1. The function will first check if the Plane can reach the Waypoint's altitude. If the Waypoint's altitude is greater than the Plane's max_altitude then return false 2. The function will then check if the Plane has sufficient fuel to move to the Waypoint. Compute number of hours = distance/speed will take to reach the Waypoint by dividing the Plane's speed b the Waypoint's distance Compute the fuel required by multiplying the number of hours by the fuel_usage fuel_required = fuel_usage*hours If the fuel required is more than the Plane's current fuel then return false Note: Make sure to subtract the fuel used before moving on to the next Waypoint =========
========= Lastly, the main function is provided as part of the template files. In the main function, we: • Prompt the user to enter the Plane's fuel, speed, fuel usage, and max altitude and create a Plane struct that holds these values • Create a Flightplan object and input the new Plane into its constructor Then, prompt the user to enter the filename that holds the waypoints • call load_waypoints from the newly created Flightplan with the filename call check_flightplan from that Flightplan, and if the result is true, print: The flight plan is valid! else print: The flight plan is not valid, please double-check your waypoints!
1 //add header guards 2 #ifndef H_FLIGHTPLAN 3 #define H_FLIGHTPLAN 4 5 //includes statements 6 7 //define the FlightPlan class 8 class FlightPlan 9 { 10 private: 11 12 public: 13 14 }; 15 16 #endif // FLIGHTPLAN Current file: flightplan.h
Current file: flightplan.cpp 1 //add nessesary includes statements 2 3 //define the member functions of the FlightPlan class
1 //add header guards 2 #ifndef STRUCTS_H 3 #define STRUCTS_H 4 5 //define the Plane struct 6 struct Plane 7 { 8 float fuel; 9 float speed; 10 float fuel_usage; 11 float max_altitude; 12 }; 13 14 //define the waypoint struct 15 struct Waypoint 16 { 17 PF 18 float heading; float distance; float altitude; 19 20 }; 21 22 #endif Current file: structs.h
File is marked as read only 1 #include "flightplan.h" 2 3 int main() 674 OWNA 4 { 5 cout << "Please enter the plane's fuel, speed, fuel usage, and max altitude:" <<endl; 6 float fuel, speed, fuel_usage, max_altitude; cin >> fuel>> speed >> fuel_usage>> max_altitude; 8 9 Plane p = {fuel, speed, fuel_usage, max_altitude); FlightPlan fp(p); 10 11 12 13 cout << "Please enter the flightplan's file name:" <<endl; string fname; cin >> fname; 14 15 fp.load_waypoints (fname); 16 17 18 19 20 21 22 23 } Current file: main.cpp if (fp.check_flightplan()){ } cout << "The flight plan is valid!"; }else{ cout << "The flight plan is not valid, please double-check your waypoints!"; return 0;
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply