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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started