You will write a simple program to track ship movement over
time. You are provided with the struct
Point defined in
You can use this point struct to help track a ship’s
Your program will read information from the user for a single boat. Specifically, you will be given its name, position (as an (x,y) pair giving its position in nautical miles from some fixed point), its heading (in degrees from north) and its speed in knots. In this scenario, the boat never changes speed or heading once set by the user. Your program will then read a number of hours from the user, update the boat's position, and print a position report after that number of hours. It will keep reading a number of hours and printing a position report over and over until the user indicates that he or she wants to quit by entering a -1. Below is a sample run of the program (user input shown in red). NOTE: several hints are given below!!!!!
Enter boat info: Slowpoke (140.3,33.7) 37.0 degrees 10 kts
Currently: Slowpoke (140.3,33.7) 37 degrees 10 kts
Time elapsed in hours: 0.5
Currently: Slowpoke (143.309,37.6932) 37 degrees 10 kts
Time elapsed in hours: 2.5
Currently: Slowpoke (158.354,57.6591) 37 degrees 10 kts
Time elapsed in hours: -1
You must make a struct
Boat that stores all the necessary information about a
boat, and make all the work (like reading and writing and moving the boat) into
functions. There should be a file
Boat.cpp that implements all of this
be very simple, and should include
(but not Boat.cpp). If you
do this right, it should be trivial to transform this program so that it would
track many boats simultaneously!
In: A screen capture of your program running on the given sample input,
and a printout of
1. Making a directory just for this homework would be a good idea.
2. Download the two files linked above and make sure they are in the current directory AND have names dbpoint.h and dbpoint.cpp
3. When you create boat.h and boat.cpp, make sure they also are in this directory.
boat.h file should have this at the very top:
and this at the very bottom:
See class 35 for details on this.
5. You will
have more than one “source” file to compile and link (main.cpp, boat.cpp, and
dbpoint.cpp). If there are only a few
files, it is reasonable to have g++ do all of this at once, which you can do by
executing the following command (result will be in a.out):
g++ -Wall -Wextra main.cpp boat.cpp dbpoint.cpp
6. WARNING 1: you should *not* list any of the .h files on the command line when you compile with g++ – only list the .cpp files, as shown in the example above.
7. WARNING 2: suppose you accidentally list dbpoint.h on the command line when you compile with g++. This will generate a “pre-compiled header” file called dbpoint.h.gch – which will then be used on your subsequent attempts at compilation, and you will then be compiling from the wrong, old header file! Don’t worry much about what this means, just a.) avoid compiling .h files directly, and b.) if you see any .gch files in your directory (like dbpoint.h.gch or boat.h.gch), delete them!
8. Remember that a compile error at, say main.cpp line 12, may actually be caused by something in another file that was included. For instance, did you forget a semicolon somewhere in boat.h? (this can cause obscure errors in main.cpp)
9. Consider how the following function might help you. You are free to use it or you may create your own from scratch.
Point move(Point position, double heading, double speed, double time)
double PI = 3.14159;
Point delta; // the displacement of the boat over the specified time
delta.x = time*speed*sin(heading*PI/180); // displacement in x direction
delta.y = time*speed*cos(heading*PI/180); // displacement in y direction
return position + delta; // requires overload of operator+ for struct Point