CSC 2210, SPA 3:
Appointments

Program Description

For this SPA you will complete a program to read appointments and print them out in sorted order where appointments are sorted (ordered) by date. The goal of the SPA is to get experience with C++ header and implementation files and separating method and function definitions from their declarations.

You do not have to know any algorithms for putting data in order ("sorting") to do this assignment. Schedule::add implements a simple algorithm known as insertion sort in which the code determines where to place each new item in a collection and then shifts the remaining items right one position to allow the new item to be inserted. This does not scale, but you will learn more effective algorithms in later courses.

To complete this assignment, do the following:

  1. Create a project and add the following files to it:
  2. Add class Date to date.h, using date.cpp to see what methods and attributes are needed. Note that the definitions of all methods will be in date.cpp - all you need to include in date.h are the prototypes. Ensure the data (_month, _day, and _year) is private and that the public interface appears before the private section. Class Date will depend on std::string, so be sure to add the appropriate #include.

    Do not put using namespace std; in date.h. It is rare for a header file to have using declarations in it.

    Note that writing the prototypes for date.h should be straightforward: you can simply copy/paste the appropriate bits of code from date.cpp and make minor edits.

    Document what class Date provides to the rest of the system in terms of its responsibilities. For example, what sorts of dates can it hold?

  3. Add a prototype for earlier to date.h.
  4. Check that date.cpp contains no errors. You will have errors in the other files, but you should be able to make date.cpp error-free at this point.
  5. Add the #ifndef lines to appointments.h and appropriate includes. Do not make changes to the classes Appointment and Schedule. See the todo example for code to follow.
  6. Comment out the incomplete while in appointments.cpp At this point, the entire system should be free of compilation errors. The program will not build - you still need to define methods and functions in appointments.cpp, but there should be no unrecognized symbols.
  7. Complete all directions marked by TODO. You can leave the TODOs in your code if you want; you may find they are helpful when double-checking that everything is complete. It is a good idea to do the TODOs in the header (.h) files before the source (.cpp) files.
  8. Build your solution and run it on test1. The output should be
            05/29/2026: boredom.begin():  start of summer break
            11/24/2026: eat turkey
            11/28/2026: start winter 16-17
            12/21/2026: break for Christmas!
            03/06/2027: spring quarter starts in 2027
            03/14/2027: pi!
            03/05/2028: start of last term for seniors...
    
  9. Modify the code to identify invalid dates. If the month is not between 1 and 12, write "ERROR: invalid month in " followed by the date. If has a valid month but the day is not in range for that month (for example, a 11/31), write "ERROR: invalid day in " followed by the date. If both the month and day are valid but the year is not between 2000 and 3000 (inclusive), write "ERROR: invalid year in " followed by the date. For simplicity, do not check for leap years; treat February as having 29 days no matter what the year is. The invalid entries are printed before the valid entries. They are printed in the order they appeared in the input. This allows you to print the invalid dates as they are encountered rather than storing them in the list of appointments and treating them as a special case. Test this on your own examples. Note there are no TODOs related to this part of the assignment.
  10. Build your solution and run it on test2. The output should be
            ERROR: invalid day in 04/31/2004
            ERROR: invalid day in 02/30/1999
            ERROR: invalid year in 01/01/1900
            02/29/2003: treated as a leap day
            05/13/2004: someone's birthday
            12/31/3000: end of time
    
    This tests some of the error checking cases.
  11. Use the search feature of your IDE to confirm that all TODO instructions have been completed.
  12. Ensure your code meets the coding standard. In particular, make sure you meet any documentation requirements specified by your instructor and make sure you minimize repeated code.
  13. Submit your solution as directed below. NOTE: this is an assignment where getting your code to compile is half the challenge. You can get 40% for this assignment just by getting your code to compile with main.cpp.

Submitting

Do not submit main.cpp - the handin system is set up to automatically include that with your solution when it builds. Use the esubmit tool, add each of your source files in any order (appointments.h, appointments.cpp, date.h, and date.cpp), and click on the Submit button. When you are finished with the code, submit a document to Canvas as directed.

Possible Issues