TDT4102, Spring 2009

Exercise 8

Deadline: 20.03.2009


The objective of this exercise:

General requirements:

Recommended reading:


Part 1: Short Recursion (20 pt.)

In this part of the exercise we will implement some easy recursion, just to get a feeling for it. These tasks might seem a bit simple for recursion to really be necessary, but we will do them recursively anyway, to get a feeling for this programming technique.

a) Create the ( recursive ) function factorial(), that takes as input an integer, and returns the product of that integer and all lower, positive integers ( 5! = ( 5 * 4 * 3 * 2 * 1 ) )
Hint: The factorial of the number n is the factorial of n-1 multiplied by n

Part 2: The apointment planner system (30 pt.)

In this part of the exercise, we will create a very simple planner system. The system will have support for creating and viewing different appointments. For this part, you do not have to worry about deleting and editing appointments.


The Appointment Class

First you will create the class Appointment. This Class will form the basis for most of this exercise. You are free to choose how you want to implement this class, but the following requirements must be fulfilled.


The Planner

Now we have support for appointments, it's time to make a Planner. The planner is, roughly speaking, a collection of appointments with some extra data and functionality. Again, the implementation and details here is up to you, but the following is required:


The System

Now it's time to put what you've done together, and create the system itself. The system will be text-based, and it should present information to the user in the console. This is also where the user should provide all the input. The system should be started when the program is run. You are free to create your own commands and visual appearance, below is an example of how this could be done:

-----

Welcome to the Planning tool, choose your command below:

l) - show a list of all appointments
m) - make a new appointment
q) - quit

user: inputs l and presses return.

-----

Showing list of appointments:

1) - 28.03 : dinner at home
2) - 30.03 : Party at Jerry's
3) - 04.04 : Clean the hobgoblin cage

b) - back

Press the number of an appointment to get more details it.

-----


Part 3: Deleting and editing appointments (30 pt.)

Now that we have a simple planner system, it's time to improve it a bit. What we'd like is the ability to delete and edit appointments already in the planner. Again you are free to implement this in the way you want to, but the following requirements must be met:


Part 4: Saving and loading our planner (20 pt.)

As it is now, the planner is of limited use - you'll have to keep it running all the time or add the appointments every time you start it! It's time to add some saving and loading. Using your skills in reading and writing files, implement this functionality. You are completely free to choose how to do this and how the data is organized in the file(s). However, the planner must be completely similar after saving and loading it! Also, all appointments should be created from the system and saved in the file - none of them should be "hard-coded" ( written directly in the code ).

Hint: This might seem a little overwhelming at first, but don't worry - you can take things one step at a time. You should probably start by saving a single appointment. You are creating both the file reader and file writer, and can also choose the format of the files. This means you can create the writer and reader at the same time, testing it as you go. When you can save an appointment, saving the entire planner is simply a matter of saving a number of such appointments consecutively, and other information you might have stored in the planner. Remember you can always create "helper" information in the file - such as the number of appointments stored in the planner. This might help you when you are reading the file!