Chapter 11 - extPersonType Class
The final struct in the Structs Project uses variables of the address and date structs as members of the
personEntry struct. It also uses another struct, person as a member:
struct person
{
string firstName;
string lastName;
};
struct date
{
int month; //range: 1 - 12
int day; //range 1-30, 1-31, 1-28, 1-29 depending on the month
int year;
};
struct address
{
string street; //Example: 123 South Main St.
string city; // Example: Newport News
string state; // The two-character postal code for the state
int zipcode; // A 5-digit number
};
struct personEntry
{
person personName;
date birthdate;
address personAddress;
string phoneNumber;
string relationship; // Friend, Family, or Business
};
For this project, convert the personEntry struct into the extPersonType class. This class will use
both inheritance and composition as shown in the inheritance diagram below:
Here are the UML diagrams that represent this class hierarchy:
As shown, the extPersonType class inherits from personType but is composed of a dateType
object variable for the birth date and an addressType object variable for the address.
Finally, here is depiction of this class structure in memory:
In the extPersonType class, getter and setter functions are only required for the phoneNumber
and relationship instance variables. Since extPersonType inherits from personType, the
name strings are members of extPersonType and are accessible through the public accessor functions
getFirstName() and getLastName(). The extPersonType class should also access the
print() function from the personType class to display the person’s name.
The function getBirthMonth() is needed to access the value of the dMonth field from the
dateType variable, birthdate. The members of dateType are not members of
extPersonType. To access a field from the birthdate variable, create a function in the
extPersonType class which uses the birthdate variable to call getMonth() from dateType.
The extPersonType class also includes two other (string) member variables. The instance variable
relationship is used to classify the person as a family member, friend, or business associate.
Restrict the values for the relationship instance variable to one of these three values:
• Family
• Friend
• Business
The second is a member variable to store the person's phone number.
The constructor for extPersonType must initialize the instance variables from the base class
(personType) as well as its instance object variables (address and birthdate). The defaults or
parameters for all the constructors are declared in the constructor for extPersonType. The
extPersonType constructor invokes the constructor for its base class and passes the appropriate
parameters by using the base class name, personType. It must also invoke the constructors for its
object variables and pass the appropriate parameters by using the name of the object variable, not the
class name as is done with inheritance. The only variables that the extPersonType constructor
initializes directly are phoneNumber and relationship.
The print() function for the extPersonType class should access the print() functions for
personType, dateType, and addressType appropriately to display the entry. The print()
function in extPersonType should produce output like this:
A program will be provided for you to test this class.