Carleton University
Department of Systems and Computer Engineering
SYSC 2002 - Winter 2011

Assignment 1

Note that to get in the habit of using file "stdstuff.h", you must start with the provided file "a1skel.cpp" (renamed to "a1.cpp"). You should make additions to (but may not remove anything from) this file. Put the Dev-C++ version of "stdstuff.h" in the same directory as your file "a1.cpp". (If you are not using Dev-C++, select the appropriate alternate version, but remember that all programs will be marked in the Dev-C++ environment in ME4390.)

A river crossing is patrolled by a patrol boat that travels in circles around a point in the middle of the river. Smugglers trying to cross the river start at the point shown on the diagram and proceed in a straight line.
                        

Let the point the patrol boat circles about be the origin of an x-y co-ordinate system.

The patrol boats starts moving from the rightmost point on its circle at t = 0 seconds and moves continuously in a counter clockwise direction thereafter. Its x and y coordinates at time t seconds are                         
where:
      x and y are both in metres
      r is the radius of the patrol radius (in m)
      vP is the patrol boat's speed (in m/s)
      important note: vPt/r is an angle in radians

Smugglers choose when to start their crossing and the angle at which they will cross the river. During their crossing, their x and y coordinates at time t seconds are given by
                        
where
      x and y are both in metres
      w is the width of the river
      θ is the "smuggler angle" in the diagram
      vS is the smuggler's speed (in m/s)
      tD is the smuggler's departure time (in seconds)

Write a function that, given vP (in m/s), θ (in radians), vS (in m/s) and tD (in seconds), computes and returns the least distance (in m) between the patrol boat and the smuggler. It is to do this by calculating the positions of the patrol boat and the smuggler at one second intervals, starting at the smuggler's departure time and continuing until the smuggler reaches the far shore. Assume that the river is 6000m wide and that the radius of the patrol boat circle is 2000m.

Note: The sample solution prints out the patrol and smuggler positions at 1 minute intervals (not 1 second intervals). However, you must still calculate the positions of the patrol boat and smuggler at 1 second intervals to find the least distance.

Write a C++ program that begins by reading the speed of the patrol boat (in km/hr). The speed must be between 10 and 50 km/hr (inclusive of these values). If it isn't your program should output an error message and have the user try again, and so on until an acceptable value are obtained.

Once the speed of the patrol boat has been obtained your program should loop, repeatedly reading in smuggler data (departure time in integer seconds, speed in km/hr, and angle in degrees) until 0 0 0 is entered. For each set of values entered, your program should output either i) an error message (if the values are unreasonable) or ii) the least distance (in m) between the patrol boat and the smuggler. Departure times cannot be negative, speeds must be between 10 and 50 km/hr (inclusive of these values), and angles must be between -20 and 20 degrees (inclusive of these values).

Note that while your function deals with speeds in metres/sec and angles in radians, speed are entered in km/hr and angles are entered in degrees. You must look after the necessary conversions.

Your program must include (and use) the function specified, and your function must conform exactly to the specification (e.g. it should NOT output the distance calculated).

To help you debug your program, the sample executable can be made to output patrol and smuggler positions. Just enter "Y" in response to the initial question. You are NOT required to implement this feature. Positions are output for the smuggler's start time and for every 1 minute afterwards.

Submit file "a1.cpp".

Updated: Tue Jan 4th, 2011 (Note added)