Question: DESCRIPTION: Using the Derived-Class.cpp file, create an additional derived class (sub class) of type Employee. The Employee class must be derived from the Person class

DESCRIPTION: Using the Derived-Class.cpp file, create an additional derived class (sub class) of type Employee. The Employee class must be derived from the Person class and include the following data items: int EmpNo; // Employee number double Hours; double PayRate; The print method for Employee needs to compute the pay based on Hours and PayRate and then display the Name, and Pay. Update the main program to include at least two employees. #include "stdafx.h" // only for Microsoft Visual C++ #include #include using namespace std; ////////////// Person class Definition ///////////////// class Person { protected: // A derived class can access protected data char Name[20]; public: Person (char* n) { strcpy_s(Name, n); } virtual void print() const { cout << "Person: " << Name << endl; } }; ///////////// Student class Definition ////////////// class Student : public Person { // access all data and functions from Person private: int units; public: // Student constructor gets name from Person class Student (char* n, int u) : Person ( n) { units = u; } virtual void print() const { cout << "Student: " << Name << " Units: " << units << endl; } }; //////////// Teacher class Definition ///////////////// class Teacher : public Person { // access all data and functions from Person private: int numberOfStudents; int numberOfClasses; public: // Teacher constructor gets 'name' from the Person class Teacher (char* n, int s, int c) : Person ( n) { numberOfStudents = s; numberOfClasses = c; } virtual void print() const { cout << "Teacher: " << Name << " Students: " << numberOfStudents << " Classes: " << numberOfClasses << endl; } }; /////////// main program /////////////////////// int main(int argc, char* argv[]) { // create objects from several different types of classes Student s1("Joe Williams", 12); Student s2("Mary Smith ", 9); Student s3("Tam Nguyen ", 10); Student s4("Jose Chavez ", 11); Teacher t1("Dan McElroy ", 28, 3); Teacher t3("Fred Jones ", 18, 2); // Create an array of pointers to different people Person *List[] = { &t1, &s2, &s3, &s4, &s2, &t3 }; int SizeOfList = sizeof(List)/sizeof(Person*); for (int i=0; iprint(); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!