I'll provide the
Sample Run Sample Input File Courses Source (filename or SCREEN): courses1.txt Finish 16.1146 nautical miles away at 340.901 degrees (from North). course 30 deg @ 10 knots for 0.5 hours course 330 deg @ 7 knots for 1.4 hours course 310 deg @ 5 knots for 0.75 hours endCourses Source (filename or SCREEN): SCREEN course 58 deg @ 9 knots for 2 hours course 110 deg @ 7 knots for 1.5 hours end Finish 25.8258 nautical miles away at 76.686 degrees (from North).
main function you must use
without modification! You will simply add in
function prototypes and definitions.
main analyzeTrip xyToBearingDist int main() { // Get data source cout << "Courses Source (filename or SCREEN): "; string source; cin >> source; // Abalyze data to find destination double x = 0, y = 0; if (source == "SCREEN") analyzeTrip(cin,x,y); else { ifstream fin(source.c_str()); if (!fin) { cout << "File not found!" << endl; exit(1); } analyzeTrip(fin,x,y); } // Report ending position double theta, r; xyToBearingDist(x,y,theta,r); cout << "Finish " << r << " nautical miles away at " << theta << " degrees (from North)." << endl; return 0; }The analyzeTrip(in,x,y)function is supposed to read the courses from streaminand store the cartesian coordinates of the final position (in nautical miles) in x and y. Note: bearing θ degrees from North is the same as angle 90 - θ from the x-axis.The xyToBearingDist(x,y,θ,r)function should convert the position in cartesian coordinates (x,y) to bearing-distance coordinates and store them in the variables θ and r. Because it's tricky to get the angle right - especially since bearing is measured clockwise from North - I'll give you a useful code fragment:double a = toDeg(atan(y/x)); if (x < 0 && y > 0) theta = 270 - a; else if (x < 0 && y < 0) theta = 270 - a; else theta = 90 - a;
Add the prototypes and definitions of the above described functions, and any helper functions you choose to define, to the above main to finish off the program.
Sample Run Sample Input File Enter file name: in1.txt **** ** ** * ** * * ** * ** * ** * *** 25 values -1 -1 0 0 1 2 3 3 4 4 4 4 3 3 2 2 1 0 -1 -2 -2 -3 -3 -3 -2Enter file name: in2.txt *** ** ** *** * * ** ** * ** * * * * * * * * * *** * * ** ** ** * * * *** * * ** ** * * *** ** * *** ** **** 68 values -3 -4 -4 -5 -5 -5 -4 -4 -3 -2 -1 0 1 2 2 3 3 3 2 2 1 0 -1 -2 -2 -3 -3 -3 -2 -2 -1 -1 -1 -2 -2 -3 -4 -5 -5 -6 -6 -6 -7 -7 -7 -7 -6 -6 -5 -4 -3 -2 -1 0 1 2 3 4 4 5 5 5 4 4 3 2 2 1
You may assume that all values are integers. The basic idea is that the first row you print corresponds to the largest value you're plotting, then next row one less than that largest value, and so on down to the last row, which corresponds to the smallest value.