Question: [C++] Finish this part. 99% done. The print method for Employee needs to compute the pay based on Hours and PayRate and then display the

[C++]

Finish this part. 99% done.

The print method for Employee needs to compute the pay based on Hours and PayRate and then display the Name, and Pay.

// Derived-Class.cpp : Defines the entry point for the console application. //

#include #include #include using namespace std;

////////////// Person class Definition ///////////////// class Person { protected: // A derived class can access protected data string Name; public: Person (string n) { // strcpy(Name, n); (Name = n); } virtual void print() const { cout << "Person: " << Name << endl; } };

///////////// Student class Definition ////////////// class Student : public Person { private: int units; public: // Student constructor gets name from Person class Student (string n,int u) : Person ( n) { units = u; } virtual void print() const { cout << "Student: " << Name << " Units: " << units << endl; } };

//////////// Teacher class Definition ///////////////// class Teacher : public Person { private: int numberOfStudents; int numberOfClasses; public: // Teacher constructor gets 'name' from the Person class Teacher (string n,int s, int c) : Person ( n) { numberOfStudents = s; numberOfClasses = c; } virtual void print() const { cout << "Teacher: " << Name << " Students: " << numberOfStudents << " Classes: " << numberOfClasses << endl; } };

//////////// Employee class Definition ///////////////// class Employee : public Person { private: int empNo; double hours; double payRate; public: // Employee constructor gets 'name' from the Person class Employee (string n,int en, double h, double pr) : Person ( n) { empNo = en; hours = h; payRate = pr; } double pay() const /* Compute regHours and overtimeHours */ { // TODO: add the missing codes here return 0; } virtual void print() const { cout << "Employee: " << Name << " Pay: $" << fixed << setprecision(2) << this->pay() << 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);

Employee e1("Thien", 123, 45, 10); Employee e2("Van", 456, 37, 20); Employee e3("Bob", 789, 29, 30); Employee e4("Smith", 012, 21, 40);

// Create an array of pointers to different people Person *List[] = { &t1, &s2, &s3, &s4, &s2, &t3, &e1, &e2, &e3, &e4 }; 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!