Homework 35 Solution
You will write a simple program to track ship movement over time. You are provided with the class Point defined in dbpoint.h and dbpoint.cpp. You can use this point class to help track a ship’s position.

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).

Also, 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 class Point
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

Requirements: You must make a class 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.h and Boat.cpp that implements all of this stuff. Your main.cpp should be very simple, and should include Boat.h (but not Boat.cpp). Remember to use conditional compilation (#ifndef, …) as necessary. If you do this right, it should be trivial to transform this program so that it would track many boats simultaneously!

Turn In: A screen capture of your program running, and a printout of Boat.h, Boat.cpp and main.cpp.