This problem set will give you practice on arithmetic and introduce you to C++ libraries. In this problem set, you will use variables to store data input by a user, perform arithmetic using the data contained within the variables, and output your findings using the terminal. Be sure to read this problem set thoroughly.
You own an airplane company that needs software to be developed for their flight systems. Specifically, the company wants to know how far their airplanes are from their airports. From your algebra classes you recall being able to find the distance between two points using either the manhattan distance:
Or the euclidean distance:
So you devise an algorithm to calculate the distance between two points (i.e. the plane and the airport) using both of these formulas as well as calculating the x-axis distance and y-axis distance so that the pilots and air traffic controllers have multiple measures of the plane’s distance.
This algorithm follows the following steps:
|x2 - x1|
(where x2 is the plane’s x-coordinate and x1 is the airport’s x-coordinate) part of the manhattan distance formula.|y2 - y1|
(where y2 is the plane’s y-coordinate and y1 is the airport’s y-coordinate) part of the manhattan distance formula.<iomanip>
.Note: The <cmath>
library must be used to calculate the absolute value, square root, and exponents.
As with every assignment your output must match CodeGrade perfectly. Below are some tips to help match the formatting:
+-----------+-----------+-------------+-------------+
"| "
, " | "
, or " |"
.An example of an interaction with your program is shown below. Your output must match this output exactly.
Alexs-iMac:A2 alex$ g++ main.cpp Alexs-iMac:A2 alex$ ./a.out Enter plane’s x coordinate: 0 Enter plane’s y coordinate: 0 Enter airport’s x coordinate: 5 Enter airport’s y coordinate: 5 Coordinates: +-----------+-----------+-------------+-------------+ | plane-x | plane-y | airport-x | airport-y | +-----------+-----------+-------------+-------------+ | 0.00 | 0.00 | 5.00 | 5.00 | +-----------+-----------+-------------+-------------+ Distances: +-----------+-----------+-------------+-------------+ | x-axis | y-axis | manhattan | euclidean | +-----------+-----------+-------------+-------------+ | 5.00 | 5.00 | 10.00 | 7.07 | +-----------+-----------+-------------+-------------+
See CodeGrade for more examples.
Note: The line breaks after the inputs in the example output formatting above are the default ones C++’s cin
and getline()
automatically apply after reading an input from the user. CodeGrade supplies input in a different manner (Linux redirection) to programs so in CodeGrade's auto tests there will not be line breaks after the inputs.
Save: Save your code as main.cpp
. Do not ignore this step or save your file(s) with different names.
Submit: Your program source code must be submitted via CodeGrade as a properly named .cpp
file prior to the deadline to receive full credit. Any submissions after the deadline will be subject to the class’ late policy.