Object Oriented Programming and Design with C++ Dr. Aaron Naiman
Course #15001301 <naiman@math.jct.ac.il>
Spring, 2006 Office hours: Monday, 13:30-14:30

Exercise Set #1


Define the following functions for non-class, non-struct angles. Have your angles be comprised of degrees, minutes (1/60 degree) and seconds (1/60 minute). The first two should be ints, and the last, a float (or double). Take care that the angle is always stored between 0° and 360°, and the minutes and seconds between 0 and 60 (non-inclusive). Have the parts of each angle be separate variables, i.e., not elements of an array.

  1. input
  2. output
  3. assignment
  4. equality check
  5. addition
  6. subtraction
  7. multiplication by a scalar
  8. bisection (forming an acute angle with the original two)

Note that aside from reporting errors, the only output occurs in the input (for instructions) and output functions.

Have your main() supply the user with a menu (iterating until s/he decides to quit), for performing the functions above. In addition, allow the user to allocate an array of such things, and then the user specifies, e.g., to perform an operation on the second and sixth elements, and place the answer in the ninth. Alternatively, the user can specify to read in/write out the array of information from/to a file (get the file name from the user!).

Note however, that the functions listed above, work on individual (1, 2 or 3) angles, and know nothing of your array. On the other hand, the switch you will have in main() will work with your array.

To assist you in getting information from the user, have a separate little library consisting of at least the following two functions:

  1. a (static) function template which receives a question (as a constant string) to prompt the user, as well as a variable into which to place the input value
  2. a function which receives a yes-or-no question to prompt the user, asking repeatedly until a (case-insensitive) proper response is recorded
Important! Think long and hard how many files of code you will have.