Exercise

 

There is not now and never will be a language in which it is the least bit difficult to write bad programs.

 
 --Unknown, 1991

This exercise will build a set of classes to describe the staff/student hierarchy in DCU. You should follow the various exercises in order, as one is dependent on the next.

The Person class Exercise

Task: Write a generic Person class, as illustrated in Figure 3.27, “The Person class.” that builds the basic functionality of the general person role in DCU.

Figure 3.27. The Person class.

The Person class.

The output of my version can be seen below, where the setTelephone() method is called:


C:\Temp>Exercise1

Name: Derek Molloy
Address: DCU, Glasnevin, D9
Telephone: 7005355

Setting Telephone Number

Name: Derek Molloy
Address: DCU, Glasnevin, D9
Telephone: 01-7005355

Solution: My version can be seen in Exercise1.cpp. Please do not look at the solution until you have had a good attempt at the exercise.

 

"Within C++, there is a much smaller and cleaner language struggling to get out."

 
 --Bjarne Stroustrup