Absolute C++ (Walter Savitch) – All chapters covered so far.
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 ) functionfactorial()
, that takes as input an
integer, and returns the product of that integer and all lower, positive integers (
5! = ( 5 * 4 * 3 * 2 * 1 )
)n
is the factorial of n-1
multiplied by n
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.
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.
An appointment must have a time and place. hint: the time can be stored simply as a string. This will ease things later.
An appointment must have a short header, showing a quick summary of the appointment.
An appointment must have a longer description.
You are free to add more fields you should be included.
All data should be private, and reached by get- and set-functions.
The class should have appropriate constructors. Decide what constructors are needed / helpful.
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:
A planner must have a list of appointments made.
It must be possible to add and remove appointments.
You are free to add more fields you think should be included.
All data should be private, and reached by get- and set-functions.
The class should have appropriate constructors. Decide what constructors are needed / helpful.
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.
-----
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:
It should be possible from the text-based system to delete appointments
It should be possible from the text-based system to edit all details of existing appointments
All existing functionality must still be present and working properly.
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!