Homework 4 - Inheritance
2020_S19/wk4/hw4.cpp
Assignment
The purpose of this assignment is to practice OOP inheritance by creating
a base class and a derived class. You will be given main.
hw4Main.cpp
Use the following list of features to code each class
Base Class - Person
Private Section:
- The Person class will have three
member variables. A staticly cstring for the name, an integer for an id,
and a staticly cstring for the email address.
Public Section:
- Default Constructor - sets the name and email to an empty
string and sets the id to zero.
- Copy Constructor - copies the member variables from the source
object
- Assignment Operator - copies the member variables from the source
object.
- bool setName(const char*) - Validate that the passed parameter only contains
letters or space, if so, copy the passed parameter to the object's
name and return true, false otherwise.
- bool setID(const int) - Validate that the passed parameter is positive, if
so, copy the passed parameter to the object's ID and return true,
false otherwise.
- bool setEmail(const char*) - Verifies that the passed email address
contains one @ character and at least one period after the @ character. If the
passed email is valid, copy the passed parameter to the object's email member
variable and return true, false otherwise.
email.
- const char* getName() const - Return the name member variable.
- const int getID() const - Return the id member variable.
- const char* getEmail() const - Return the email member variable.
- void inputPerson() - Promps the user for the name, id, and email address.
Use the mutator member functions to set the values. If any of the mutator
functions return false, allow the user to re-enter for that member variable.
- void printPerson() const - Use accessors to print the name, id,
and email.
Derived class - Student
This class inherits from the Person class publicly. It defines a student
with a major and gpa.
Private Section:
- The Student class will have two member variables, in addition to the
inherited member variables. A staticly sized cstring for the student's major
and a float for the student's gpa.
Public Section:
- Default Constructor - Sets the member variable major to an empty string
and sets gpa to zero. Invokes the parent default constructor to initialize
name, id, and email.
- Copy Constructor - Copies the members of the passed source object.
Invokes the parent copy constructor to copy the name, id, and email.
- Assignment Operator - Calls the parent assignment operator to copy
the name, id, and email of the passed source object. Then copies the major
and gpa of the passed source object.
- bool setMajor(const char*) - Verifies that the passed cstring contains
all letters or space characters. If so, assign the passed parameter to
major and return true, false otherwise.
- bool setGpa(const float) - Verifies that the passed float is within
range of 0.0..4.0. If so, assign the passed parameter to the gpa and return
true, false otherwise.
- const char* getMajor() const - Returns the major.
- const float getGpa() const - Returns the gpa.
- void inputPerson() - Calls the parent version of inputPerson to read
in the name, id, and email address. Then prompt for the major and gpa.
Use the mutator member functions to set the values. If any of the mutator
functions return false, allow the user to re-enter for that member variable.
- void printPerson() const - Calls the parent version of printPeron to print the
name, id, and email address. Use the accessor member functions to
print out the student's major and gpa up to two decimal points.
Derived Class - Faculty
This class inherits from the Person class publicly. It defines a faculty
with department and salary
Private Section:
- The Faculty class will have two member variables, in addition to the
inherited member variables. A staticly sized cstring for the faculty's
department and a float for the faculty's salary.
Public Section:
- Default Constructor - Sets the member variable department to an
empty string and sets salary to zero. Invokes the parent default
constructor to initialize name, id, and email.
- Copy Constructor - Copies the members of the passed source object.
Invokes the parent copy constructor to copy the name, id, and email.
- Assignment Operator - Calls the parent assignment operator to copy
the name, id, and email of the passed source object. Then copies the
members of the passed source object.
- bool setDepartment(const char*) - Verifies that the passed cstring contains
all letters or space characters. If so, assign the passed parameter to
department and return true, false otherwise.
- bool setSalary(const float) - Verifies that the passed float is positive.
If so, assign the passed parameter to the salary and return
true, false otherwise.
- const char* getDepartment() const - Returns the department.
- const float getSalary() const - Returns the salary.
- void inputPerson() - Calls the parent version of inputPerson to read
in the name, id, and email address. Then prompt for the department and
salary.
Use the mutator member functions to set the values. If any of the mutator
functions return false, allow the user to re-enter for that member variable.
- void printPerson() const - Calls the parent version of printPeron to print the
name, id, and email address. Use the accessor member functions to
print out the faculty's department and salary up to two decimal points.