Programming Assignment 3 - Object Composition

Appointment, Date and Time Classes

Due March 7, 2010

Overview

For this project you will learn how to compose classes, e.g. make classes out of other classes. In this case you will create a "Appointment" class, which stores information about appointments. An appointment will contain the description of the appoints (a string), the start time and end time (using a TimeOfDay class), and a date (using the previous defined date class). In this assignmetn you use the Date class, and implement a TimeOfDay class similar to the date class. Then these will be incorporated into the Appointment class. You will write a driver program to completely test the group of classes.

Instructions

  1. Modify the Date class so it includes a before comparison operation:
    1. bool before(Date const & time) const
      Return true if the current object is before (date-wise) the date of the parameter object .
  2. Write a file TimeOfDay.h that defines the TimeOfDay class. It must have 3 private integers to hold the hour, minutes, and seconds. The TimeOfDay will ONLY store valid times between 0:0:0 and 23:59:59. It also needs the following functions:
    1. TimeOfDay()
      Default constructor which initializes the time to 0:0:0 (midnight).
    2. TimeOfDay(int h, int m, int s)
      Constructor which takes in values for hour, minute, and second.
    3. ~TimeOfDay()
      Default destructor. Does it need to do anything?
    4. int getHour() const, int getMinute() const, int getSecond() const
      Accessor functions for each of the data members.
    5. bool setTime(int h, int m, int s)
      Sets the time object if provided with valid time values, otherwise it leaves the time object alone and returns false.
    6. bool equals(TimeOfDay const & time) const
      Return true if the current object and the parameter object represent the same time.
    7. bool before(TimeOfDay const & time) const
      Return true if the current object is before (time-wise) the time of the parameter object .
    8. void increment()
      Add 1 second to the current time. If 23:59:59, then 00:00:00;
    9. void add(int n)
      Adds n number of second to the current time. If the number of seconds will move the time beyond 23:59:59, print error message, and wrap into next day(s) (e.g. 20:00:00 + 18,000 seconds (5 hours) will go to 1:00:00, or one hours into the next day).
    10. void sub(int n)
      Subtracts n number of seconds from the current time. If the subtraction would return a time before 00:00:00, print an appropriate error message and set the time to 0:0:0.
    11. void displayTime() Display the time!
  3. You will need a file called TimeOfDay.cpp that implements the above functionality.
  4. You will write your own tests in a main function inside testTime.cpp to test all functionality of your time class.
  5. Create an Appointment class. This class private members for the appointment description, and start and end times of the appointment, and the date. Write a file Appointment.h that defines the Appointment class. It must have 4 private values: A string description apptDesc, two Times, startTime and endTime, and a Date, apptDate. Appointment will need to include the Date and TimeOfDay header files so that it can use them.
    1. Appointment() Default constructor which initializes the appointment to an empty description, and default dates and times.
    2. Appointment(string des, TimeOfDay start, TimeOfDay end, Date d)
      Constructor which takes in values for the appointment.
    3. string GetDescription () const
      Accessor function to get the description of the appointment.
    4. TimeOfDay GetStartTime () const
      Accessor function to get the start time of the appointment.
    5. TimeOfDay GetEndTime () const
      Accessor function to get the end time of the appointment.
    6. Date GetDate () const
      Accessor function to get the date of the appointment.
    7. void DisplayAppointment () const
      Output function which displays the appoint. Output in an attractive form. Include the duration.
  6. Write a program testAppointment.cpp which uses the new appointment class:
    1 Write a function GetAppointment(Appointment &a) that prompts the user for the appointment information, and returns a completed appointment object. It should not allow the user to enter an invalid appointment, re-asking for each field until it is correct.
    1. In main() define two appointments. Appt1 and Appt12.
    2. Use GetAppointment() to set them up the two appointment objects.
    3. Use the equals function to report if the appointments are at the same start time and date.
    4. Use the equals function to report if the appointments are at the same end time. and date
    5. Use the before function to report if the appointments are overlapping.
    6. If the two appointments are not equal or overlapping display the two appointments in their order of occurance.
  7. Turn in all files, and a screen capture of the test.
Extra Credit: If you implemented the Time difference function you can get extra credit for adding this:
  • TimeOfDay GetDuration () const
    Accessor function to get the time duration of the appointment.
-- JimSkon - 2011-02-24
Topic revision: r11 - 2011-03-18 - JimSkon
 
This site is powered by the TWiki collaboration platformCopyright &© by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback