Homework 5
~/2020_S19/wk5/hw5.cpp
The purpose of this assignment is to practice aggregation, inheritance, and
polymorphism.
You will use the given Person, Faculty, and Student
classes and alter the definitions to add polymorphic behavior.
In addition, you will write an
Abstract Base Class called 'CourseInterface' (parent),
a derived 'Course' class (child),
and two derived-derived classes called 'Lecture' and 'Lab'
(grand children). The description of the classes are
listed below. Function main will also be given to you with a ClassInfo
class.
hw5.cpp main
CourseInterface (Abstract Base Class)
This class will contain pure virtual member
functions for the derived class's public interface. In addition to
protected member variables: a statically sized cstring for 'title' and 'type',
a Faculty object 'lecturer', a PersonStudent pointer 'roster', and an integer
for 'count' number of students enrolled, and and integer for 'capacity'.
- CourseInterface() - Default constructor: set the first
character member variable 'Title' to NULL. Allocate CLASSROOM_CAP Student
objects to the Student pointer (Use a defined constant and set
CLASSROOM_CAP to 35). Set count and capacity to 0.
- CourseInterface(const CourseInterface&) - Copy constructor:
copy
the static member variables. Also, if the passed object's roster
is not NULL, allocate a new Student array to 'roster', traverse
and copy passed object's roster array.
- void operator=(const CourseInterface&) - Overloaded Assignment Operator:
if the address of the passed object is the same, return. Otherwise,
if 'roster' is NOT NULL, deallocate the 'roster' array and set to NULL.
Copy the static member variables. Also, if the passed object's roster
is not NULL, allocate a new Student array to 'roster', traverse
and copy passed object's roster array.
- ~CourseInterface() - Destructor: deallocate the Student array
and set the Student pointer to NULL.
- void setTitle(const char*) - copy the passed argument to set the
'title' member variable.
- void setType(const char*) - copy the passed argument to set the
'type' member variable.
- const char* getTitle() const - return the 'title' member variable
- const int getCount() const - return 'count'.
- const char* getType() const { return 'type'.
- void inputCourse() = 0 - Pure virtual member function. To be
defined in derived class. This will act as a driver function to
input the course information (set title, set Faculty, allocate Student array,
set each Student).
- void printCourse() = 0 - Pure virtual member function. To be
defined in derived class. This will act as a driver function to
output the course information (print course title, type, print Faculty object,
print class roster).
Course (Derived)
This class will inherit from CourseInterface publically.
- Course() - default constructor: invoke parent default constructor.
- Course(const Course&) - copy constructor: invoke and pass to parent
copy constructor.
- void operator=(const Course&) - Overloaded Assignment Operator:
call the parent's version of the overloaded operator with
passed Course argument.
- ~Course() - destructor: empty definition.
- void inputCourse() - In this function you will prompt the user
for the course title and set the title with the corresponding mutator
function. Call the Faculty member function 'inputPerson' to set
the Faculty object. Prompt the user for a positive number that is less than
CLASSROOM_CAP and validate. Traverse the defautly allocated 'roster' array
and call the Student member function 'inputPerson' for each Student object
within the array.
- void printCourse() - With nicely fomatted output, print the
course title, type, lecturer, and each student within the 'roster' array.
Lecture (Derived-Derived)
This class will inherit from Course publically
- Lecture() - default constructor: invoke parent default constructor and
call the mutator function for 'type' and pass it string literal "Lecture".
- Lecture(const Lecture&) - copy constructor: invoke and pass to parent copy
constructor and call the mutator function for 'type' and pass it string
literal "Lecture".
- ~Lecture() - destructor: empty definition.
- void operator=(const Course&) - Overloaded Assignment Operator:
call the parent's version of the overloaded operator with passed
Lecture object Argument.
Also, call the mutator function for 'type' and
pass it string literal "Lecture".
Lab (Derived-Derived)
This class will inherit from Course publically, and will contain
one Faculty member object 'labInstructor'.
- Lab() - default constructor: invoke parent default constructor.
Assign the
Faculty member object 'labInstructor' to be the Course's 'lecturer' member
object by default. Also, call the mutator function for 'type' and pass it
string literal "Lab".
- Lab(const Lab&) - copy constructor: invoke and pass to parent copy
constructor. Assign the Faculty member object 'labInstructor' to be the
passed object's member.
Also, call the mutator function for 'type' and
pass it string literal "Lab".
- ~Lab() - destructor: empty definition.
- void operator=(const Course&) - Overloaded Assignment Operator:
call the parent's version of the overloaded operator with passed
Lab object Argument. Also, call the mutator function for 'type' and
pass it string literal "Lab".
- void inputCourse() - overridden function: call the member function
'inputPerson' of the member object 'labInstructor'. Then call the parent's
version of inputCourse.
- void printCourse() - overridden function: For this version of
printCourse, you will print the course title, type, lab instructor, and
each student object in the roster array.
- void inputLabFaculty() - this function will call the member function
'inputPerson' of the member object 'labInstructor'.
CourseInfo
This class definition is given to you. Aggregation is the instance
of a class within another class ("has a" relationship). A CourseInfo
object will contain an instance of a Lecture and a Lab object.
~/2020_S19/wk5/hw5.cpp
Be sure that the directory name and file name are exact!