Question & Answer: Step 1: Write a class called Administrator which is to be derived from the class SalariedEmp which is derived from Employee……

IN C++. (hourlyemp.h in the codes is not necessary for the assigment)

Step 1: Write a class called Administrator which is to be derived from the class SalariedEmp which is derived from Employee.

Use these files:

employee.h

employee.cpp

salariedEmp.h

salariedEmp.cpp

empTest.cpp

Your Administrator class should have the following additional members:

A data member of type string that contains the administrator’s title (such as Director or Vice President).

A data member of type string that contains the company area of responsibility (such as Production, Accounting, or Personnel).

A data member of type string that contains the name of this administrator’s immediate supervisor.

A default constructor that initializes ALL of the data members to empty strings, as well as a constructor that allows the client programmer to provide values for ALL of the data members.

A member function called changeSupervisor which changes the supervisor name.

A member function for reading in the administrator’s information from the keyboard. The user should be prompted for each piece of information. This should include information to fill in the data members derived from other classes, such as the name of the administrator.

A member function called print which outputs the administrator’s data to the screen.

A redefinition of the member function printCheck() with appropriate notations on the check. This function will look a lot like the print member function, except that the output will look like a check. Base this output on the printCheck() function in the base class. The check itself will not change from how it looks in the base class. The check stub, however, should include information such as the administrator’s title, area of responsibility, and supervisor.

// this is the file "employee.h"
         
     #ifndef EMPLOYEE_H
     #define EMPLOYEE_H
     #include <string>
     using namespace std;

     class employee {
         public:
             employee();
             employee(const string& newName, const string& newSsn);    
             string getName() const;
             string getSsn() const;
             void changeName(const string& newName);
             void changeSsn(const string& newSsn);
         private:
             string name;
             string ssn;
             double netPay;
     };
     
     #endif
// this is the file "employee.cpp"
     
     #include "employee.h"
     #include <string>
     using namespace std;
     
     employee::employee()
     {
         netPay = 0;
     }

     employee::employee(const string& newName, const string& newSsn)    
     {
         name = newName;
         ssn = newSsn;
         netPay = 0;
     }

     void employee::changeName(const string& newName)
     {
         name = newName;
     }

     void employee::changeSsn(const string& newSsn)
     {
         ssn = newSsn;
     }

     string employee::getName() const
     {
         return name;
     }

     string employee::getSsn() const
     {
         return ssn;
     }
// this is the file "salariedemp.h"
     
     #ifndef SALARIEDEMP_H
     #define SALARIEDEMP_H
     #include "employee.h"
     #include <string>
     using namespace std;

     class salariedEmp : public employee {
         public:
             salariedEmp();
             salariedEmp(const string& newName,
                              const string& newSsn,
                              double newWeeklySalary);    
             void printCheck() const;
             void giveRaise(double amount);
         protected:
             double salary;
     };


     
     #endif
// this is the file "salariedemp.cpp
    
    #include "salariedemp.h"
    #include "employee.h"
    #include <iostream>
    using namespace std;
    
    void salariedEmp::giveRaise(double amount)
    {
        salary += amount;
        netPay += amount;
    }

    salariedEmp::salariedEmp()
    {
        salary = 0;
        netPay = 0;
    }

    salariedEmp::salariedEmp(const string& newName,
                             const string& newSsn,
                             double newWeeklySalary)    
                                        
    : employee(newName, newSsn)
     

    {
        salary = newWeeklySalary;
        netPay = salary;
    }


    void salariedEmp::printCheck() const
    {
        cout << "pay " << name << endl;
        cout << "the sum of " << netPay << " Dollars." << endl;    
        cout << "Check Stub: " << endl;
        cout << "Employee number: " << ssn << endl;
        cout << "This is a salaried employee.  Regular pay: "
             << salary << endl;
    }
// this is the file emptest.cpp
    
    #include <iostream>
    #include "hourlyemp.h"
    #include "salariedemp.h"
    using namespace std;

    int main()
    {       
        hourlyEmp arnold("Arnonld Jones","23456664",13,20);    
        arnold.setHours(10);
        cout << "Check for " << arnold.getName() << " for "
             << arnold.getHours() << " hours:" << endl;
        arnold.printCheck();
    
        cout << endl << endl << endl;
        
        arnold.giveRaise(5);
        cout << "Check for " << arnold.getName() << " for "
             << arnold.getHours() << " hours:" << endl;
        arnold.printCheck(); 
        
        cout << endl << endl << endl;
                 
        salariedEmp sally("Sally Wu", "345123456", 1234.45);    
        cout << "Check for " << sally.getName() << endl;
        sally.printCheck();
        
        cout << endl << endl << endl;
        
        sally.giveRaise(10);
        cout << endl << endl << endl;
        cout << "after a raise of 10, Sally's check:" << endl;
        sally.printCheck();
    }   

Expert Answer

 

Base Class Employee have the data members netpay, name and ssn are defined as a private data members.
As per OOPS principles class private data cann’t be access outside the class.
But Salaried employee is trying to modify the Employee class data members .
Because of these things your code is giving errors.

But i have written the below code as specified in problem statement
1. Created Admin class with data members
2. Created default and parametrised constructors.
3. Crated the changeSupervisorName function.
4. Define print and printCheck and setAdminstratorInfo methods.

First Please correct the given code and then add this code with exiting code..
then it works fine.

class Administrator : public SalariedEmp
{
string title;
string responsibility;
string immediate_supervisor;
public :
// Default Constructor
Administrator()
{
title = ” “;
responsibility = ” “;
immediate_supervisor = ” “;
}
// Parametrised Constructor
Administrator(string ti, string res, string imme)
{
title = ti;
responsibility = res;
immediate_supervisor = imme;
}

// This function will change the name of the immediate_supervisor name
void changeSupervisorName(string name)
{
immediate_supervisor = name;
}
// Set the name of the Administrator by passing information to Base class name of the employee with
// help of salariedEmp constructor
void setAdminstratorInfo(string newName): salariedEmp(newName)
{
}

// print the Administrator information
void print()
{
cout<<“Administrator Title :”<<title<<endl;
cout<<“Administrator Responsibility :”<<responsibility<<endl;
cout<<“Administrator Immediate Supervisor :”<<immediate_supervisor<<endl;
}

// Redefine the Employee printCheck method from SalariedEmp class
void printCheck()
{
cout << “Name ” << name << endl;
cout << “the sum of ” << netPay << ” Dollars.” << endl;
cout << “Check Stub: ” <<“Administrator Title “<< title <<“Administrator Responsibility ”
<<responsibility << “Administrator Immediate Supervisor “<< immediate_supervisor<<sendl;
cout << “Employee number: ” << ssn << endl;
cout << “This is a salaried employee. Regular pay: ” << salary << endl;
}

};

Still stressed from student homework?
Get quality assistance from academic writers!