OO Encapsulation  «Prev  Next»

Design a Person class - Exercise

Design a person class

Objective: Design a class called person that contains members to store data and a member function to print out the data members.


Include the following data members for storing data:
  1. name
  2. age
  3. gender
  4. some form of identification number, such as social security number or national insurance number
Include the following member function:
print, which will print out the values of the previous four data members in an easily readable format

Note: Since we have not discussed declaring external member functions in much detail, make this function internal to the class.

Further considerations

The class specification for this exercise are rather incomplete. As it stands, all the data is stored as private and there are no member functions to assign values to this data. While not required for this exercise, add any other data members that you think might be useful to a person class. You could also write a member function that calculates the current age of the person instead of storing the age as a data member. If you do this, what other data members would you need?
Paste your person class below and click the
Submit button when you are ready to submit this exercise.