CS1003 Homework #5
Due by Tuesday, April 20, at 11:00am

There are two parts to this homework assignment: a theory portion, worth 10 points, and a programming portion, worth 15 points. Please be sure to review the submission instructions in advance, and make sure to include a README.

This version is revised as of 4/12. Minor clarification on getHour and getMinute: they take integer representations of times, not dates; and to listAllEvents: it needs one parameter. Also added more tips on how to use sscanf and printf.

Written questions

  1. (3 points) Insert the following elements into a binary search tree, and draw the result: 72, 35, 61, 10, 4, 98, 32, 55
  2. (4 points) You're given the following buggy snippet of code:
    int a = 5, *b = &a, *c = &b;
    printf("%d\n", *c);
    1. (2 points) Without running this snippet, describe why this code has a bug, and suggest what the program might output.
    2. (2 points) Suggest a change to this program that would fix this bug and give correct output, and explain why it would work.
  3. (3 points) You're given the following elements sitting in a stack: 45, 57, 12, 9, 32, 10, 5 -- such that 45 is at the "top" of the stack (i.e., the first element to be popped). Now, for every element in this stack, we pop that element and push it into a second stack. Once the first stack is empty, we now pop each element in the second stack and print them out, one by one. In what order are the numbers printed, and why?

Programming assignment: calendaring program

In this assignment, you're going to build a simple program that will be able to store and list appointments, as well check for simple scheduling conflicts (i.e., overlapping appointments). In order to accomplish this, we will build a hierarchical data structure and manipulate it appropriately.

For simplicity's sake, we will impose some restrictions on our calendar program. First, it will only store one year's information; in fact, you don't need to encode year anywhere inside the program. Second, in order to detect conflicts, we're going to represent times as ints, not strings or complex time structures -- so, 12:15 might be represented as the integer "1215", while 6:05 might be represented as the integer "605". By doing so, we can easily check to see if events overlap while adding them. We will also assume military time (i.e., no AM/PM designators), and will assume valid input (i.e., the user's not going to specify 2/31 at 64:05).

  1. (4 points) Design the data structures for this assignment. You will need the following:
  2. (3 points) Build an addEvent function that takes four parameters: a pointer to a day structure, the name of the event, and the start and end times defined as ints. Have it return an int representing the success of the addEvent -- in particular, have it fail if there is either a conflict or if there is no more array space for events on that day. (In order to determine scheduling conflicts, you'll have to scan the list of existing events for that day and compare the times against the new event to be added.)
  3. (2 points) Build three functions -- timeToInt, which takes the hour and minute as separate parameters and returns an int that combines the two; getHour, which extracts the hour from the integer time, and getMinute, which extracts the minute from the integer time.
  4. (2 points) Build a listEvent function that takes one parameter -- a pointer to a day structure -- and prints out the date (excepting year), followed by the events for that day. Make sure to convert the time integers into individual constitutients so that you can print out the times in a human-readable form.
  5. (2 points) Build a listAllEvents function that takes one parameter -- a pointer to the entire calendar structure -- and prints out all of the events in the calendar. Have it repeatedly call listEvent to do so.
  6. (2 points) Build a user interface inside main that allows the following functions. Use a methodology similar to the previous homeworks.
Here are some hints you may find helpful. (5 points extra credit) Create a new add feature called "Add in next midday slot", which takes a date and the name of an appointment and actually scans for the next available slot between 9AM and 5PM. You can assume hourly intervals. If you do this, make sure to add a new user-interface option and leave the regular add user interface option alone.