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 #2


Define an angle class, 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 degrees is always stored between 0° and 360° (non-inclusive), and the minutes and seconds between 0 and 60 (non-inclusive).

Define also the following member functions:

  1. a default constructor which can also take 1, 2 or 3 arguments
  2. a copy constructor
  3. a destructor
  4. to view each of the data members (3 functions)
  5. to modify each of the data members (3 functions)
  6. the assignment operator
  7. the equality-test operator
  8. to pretty-print the object
  9. to get object data values from user
  10. to return the angle in radians
Define in addition a global function which receives an angle as an argument, and calculates and returns the angle in radians. Use the same function names for the global and member functions.

Note: have the corresponding view and modify functions use the same names, taking advantage of overloading. E.g., a consistent naming scheme might be _foo for the data member, and foo() for the corresponding view and modify member functions.

Define main() to invoke all of the functions defined, with all possible forms (i.e., possibilities of default values). Be creative. Note that main() will be in a separate file. (How many files does that make it so far?)

You may want to use a small I/O library you have tucked away somewhere, to assist with the user input. ("Hmm, what does he mean?")