Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this program (C++) Don’t add anything extra to the program(s) a

ID: 3715990 • Letter: I

Question

I need help with this program (C++)

Don’t add anything extra to the program(s) and implement the code as described above.

Submission will be as one main CPP program with separate class files (class implementation files .cpp and header files .h). There will be 7 files to submit

In this lab, you will assign dynamically allocated derived class objects to base class pointers and use polymorphism to display output based on the type of the object. (10 points) First, start by implementing the base class Employee. This class will have: One private int attribute empID One public constructor that will take an int as an argument and assign it to empIID A public function that will return the empID with the following prototype: int getEmpID const; A public pure virtual function with the following prototype: virtual void printPay 0; Next, implement the derived class HourlyEmployee: public Employee. (10 points) This class will have One private double attribute hours One private double attribute payRate One public constructor that will take in three arguments: The employee id, the number of hours worked, and the pay rate. The constructor will pass the employee id argument to the base class constructor and assign the value of the other two arguments to its attributes. A public function that will return the hours with the following prototype double getHours ) const; A public function that will return the payRate with the following prototype: double getPayRate ) const: An overridden public printPay function that will print the hourly empolyee's id number and the weekly pay (i.e. hours payRate) with 2 digits after the decimal place. The prototype is: void printPay O;

Explanation / Answer

//main.cpp
#include <iostream>
#include <iomanip>
#include <vector>

#include "Employee.h"
#include "HourlyEmployee.h"
#include "SalariedEmployee.h"

using namespace std;

void getInput(vector <Employee *> & Ve);
void printList(const vector <Employee *> & Ve);

int _main(int argc, _CHAR* argv[])
{
   vector<Employee *> list;
   getInput(list);
   printList(list);
   cout << "Lab 7 " << endl;
   system("pause");
   return 0;
}

void getInput(vector <Employee *> & Ve){
   int choice;
   int id = 0;
   double hours = 0.0, payrate = 0.0, salary = 0.0;
   do{
       cout << "Enter 1 for Hourly Employee Enter 2 for Salaried Employee Enter 3 to stop: ";
       cin >> choice;
       if (choice == 1)
       {
           cout << "Enter Employee ID: ";
           cin >> id;
           cout << "Enter Employee hours: ";
           cin >> hours;
           cout << "Enter Employee payrate: ";
           cin >> payrate;
           Employee* temphourly = new HourlyEmployee(id, hours, payrate);
           Ve.push_back(temphourly);
       }
       else if (choice == 2)
       {
           cout << "Enter Employee ID: ";
           cin >> id;
           cout << "Enter Employee salary: ";
           cin >> salary;
           Employee *tempsalary = new SalariedEmployee(id, salary);
           Ve.push_back(tempsalary);
       }
       else if (choice == 3)
       {
           break;
       }
       else cout << "Invalid input" << endl;

   } while (true);
}

void printList(const vector <Employee *> & Ve)
{
   for (vector < Employee *>::const_iterator it = Ve.begin(); it != Ve.end(); ++it)
   {
       (*it)->printPay();
   }
}
------------------------------------------------------------------
//Employee.cpp
#include "Employee.h"

Employee::Employee(int _empID)
{
    this->empID = _empID;
}

int Employee::getEmpID() const
{
    return this->empID;
}
---------------------------------------------------------------
//Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

class Employee{
private:
    int empID;
public:
    Employee(int _empID);
    int getEmpID() const;
    virtual void printPay() = 0;
};

#endif
---------------------------------------------------------------------
//SalariedEmployee.cpp
#include <iostream>
#include <iomanip>

#include "SalariedEmployee.h"
#include "Employee.h"

using namespace std;

SalariedEmployee::SalariedEmployee(int _empID, double _salary) : Employee(_empID), salary(_salary) {}

double SalariedEmployee::getSalary() const{
    return this->salary;
}

void SalariedEmployee::printPay(){
    //id and weekly pay 2 decimals
    cout << "Employee ID: " << getEmpID() << " Weekly pay: $" << std::setprecision(2) << std::fixed << salary / 52 << endl;
}
-------------------------------------------------------------------
//SalariedEmployee.h
#ifndef ABSALARIEDEMPLOYEE_H
#define ABSALARIEDEMPLOYEE_H

#include "Employee.h"

class SalariedEmployee :public Employee{
private:
    double salary;
public:
    SalariedEmployee(int _empID, double _salary);
    double getSalary() const;
    virtual void printPay();
};

#endif
--------------------------------------------------------
//HourlyEmployee.cpp
#include <iostream>

#include "Employee.h"
#include "HourlyEmployee.h"

using namespace std;

HourlyEmployee::HourlyEmployee(int _empID, double _hours, double _payRate) : Employee(_empID), hours(_hours), payRate(_payRate) {}

double HourlyEmployee::getHours() const{
    return this->hours;
}

double HourlyEmployee::getPayRate() const{
    return this->payRate;
}

void HourlyEmployee::printPay(){
    cout << "Employee ID: " << getEmpID() << " Weekly pay: $" << hours * payRate << endl;
}
---------------------------------------------------------
//HourlyEmployee.h
#ifndef HOURLYEMPLOYEE_H
#define HOURLYEMPLOYEE _H

#include "Employee.h"

class HourlyEmployee :public Employee{
private:
    double hours;
    double payRate;
public:
    HourlyEmployee(int _empID, double _hours, double _payRate);
    double getHours() const;
    double getPayRate() const;
    virtual void printPay();
};

#endif