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

Using C++, Design a class named Employee. The class should keep the following in

ID: 3864292 • Letter: U

Question

Using C++,

Design a class named Employee. The class should keep the following information in

Employee name

Employee number

Hire date

Write one or more constructors and the appropriate accessor and mutator functions for the class.

In a particular factory a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals.

Design a ShiftSupervisor class that is derived from the Employee class. The ShiftSupervisor class should have a member variable that holds the annual salary and a member variable that holds the annual production bonus that a shift supervisor has earned.

Write one or more constructors and the appropriate accessor and mutator functions for the class. Demonstrate the class by writing a program that uses a ShiftSupervisor object.

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;

class Employee
{
    //variables
    private:
    char name[30];
    int empNum;
    string hiredate;

    public:
    //constructor
    Employee(char name[30],int empNum,string hiredate)
    {
        strcpy(this->name,name);
        this->empNum = empNum;
        this->hiredate = hiredate;
    }
    //set and get methods
    void setName(char name[30])
    {
        strcpy(this->name,name);
    }
    void setEmpNum(int empNum)
    {
        this->empNum = empNum;
    }
    void setHiredate(string hiredate)
    {
        this->hiredate = hiredate;
    }
  
    char* getName()
    {
        return name;
    }
    int getEmpNum()
    {
        return empNum;
    }
    string getHiredate()
    {
        return hiredate;
    }
    void display()
    {
        cout<<" Name: "<<getName();
        cout<<" Employee number: "<<getEmpNum();
        cout<<" Hire date: "<<getHiredate();
    }
  


};

class ShiftSupervisor :public Employee
{
    private :
    double annualSalary;
    double annualProductionBonus;
  
    public:
    //passing parameters to base class Employee from derived class ShiftSupervisor
    ShiftSupervisor(char name[30],int empNum,string hiredate,double annualSalary,double annualProductionBonus):Employee(name,empNum,hiredate)
    {
        this->annualSalary = annualSalary;
        this->annualProductionBonus = annualProductionBonus;
    }
    //get and set functions
    void setAnnualSalary(double annualSalary)
    {
        this->annualSalary = annualSalary;
    }
    void setAnnualProductionBonus(double annualProductionBonus)
    {
        this->annualProductionBonus = annualProductionBonus;
    }
  
    double getAnnualSalary()
    {
        return annualSalary;
    }
    double getAnnualProductionBonus()
    {
        return annualProductionBonus;
    }
    void displayDetails()
    {
        display(); //call to Employee class function
        cout<<" Annual Salary: $"<<getAnnualSalary();
        cout<<" Annual Production Bonus: $"<<getAnnualProductionBonus();
    }
  
  
  
};

int main()
{
    ShiftSupervisor ss("John Doe",859,"7/24/2014",75000,15000);
    cout<<fixed<<setprecision(2); //use manipulator functions
    ss.displayDetails();
  
   return 0;
}


Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote