using C++ programming Derive an Administrator class from SalariedEmployee in sto
ID: 3842508 • Letter: U
Question
using C++ programming
Derive an Administrator class from SalariedEmployee in stored in the files section on canvas.You'll need to download the files employee.cpp, employee.h, salariedemployee.cpp, andsalariedemployee.h. You can find these in Canvas under Files HWHW8codeI
t is allowed (actually, it is recommended) to change the protection qualifier private toprotected in the base class.
Supply the following additional data and function members.
A variable of type string named title to contain the administrator's title. Examples:
Director, Vice President
A variable of type string named responsibility to hold the name of the area of
responsibility of the administrator. Example: Finance, Accounting, and Personnel.
A variable of type string named supervisor to hold the name of the administrator's
immediate supervisor.
A protected member variable of type double to hold the administrator's annual
salary.
A member function, setSupervisor, to change the name of the supervisor.
A member function to allow keyboard entry of the administrator's data.
A member function, print, that does screen display of administrator's data.
An overloaded member function printCheck() to print the administrator's data on the
check.
Write a main function to test all the member functions and functionality of your derived class.
Explanation / Answer
Note: Mentioned code content is not given, code is prepared generally.
Solution:
//employee.h:
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include<string>
#include<cstdlib>
#include<iostream>
using std::string;
namespace SavitchEmployees
{
class Employee
{
public:
Employee();
Employee(const string& theName, const string& theSsn);
string getName() const;
string getSsn() const;
double getNetPay() const;
void setName(const string& newName);
void setSsn(const string& newSsn);
void setNetPay(double newNetPay);
void printCheck();
protected:
string name;
string ssn;
double netPay;
};
}
#endif
//employee.cpp
#include<string>
#include<cstdlib>
#include<iostream>
#include "employee.h"
using std::string;
using std::cout;
namespace SavitchEmployees
{
Employee::Employee():name("No name yet"),ssn("No number yet"),netPay(0)
{
//deliberately empty
}
Employee::Employee(const string& theName, const string& theNumber):name(theName),ssn(theNumber), netPay(0)
{
//deliberately empty
}
string Employee::getName() const
{
return name;
}
string Employee::getSsn() const
{
return ssn;
}
double Employee::getNetPay() const
{
return netPay;
}
void Employee::setName(const string& newName)
{
name=newName;
}
void Employee::setSsn(const string& newSsn)
{
ssn=newSsn;
}
void Employee::setNetPay(double newNetPay)
{
netPay=newNetPay;
}
void Employee::printCheck()
{
std::cout<<" Error: printCheck Function CALLED FOR AN "
<<"UNDIFFERENTIATED EMPLOYEE. Aborting the program. "
<<"Check with the author of the program abou this bug. ";
exit(1);
}
}
//salariedemployee.h
//This is the header file salariedemployee. h.
//This is the interface for the class SalariedEmployee.
#ifndef SALARIEDEMPLOYEE H
#define SALARIEDEMPLOYEE H
#include <string>
#include "employee.h"
using std::string;
#include<iostream>
#include<string>
using std::string;
using std::cout;
using std::endl;
namespace SavitchEmployees
{
class SalariedEmployee:public Employee
{
public:
SalariedEmployee();
SalariedEmployee(const string& theName, const string& theSsn, double theWeeklysalary);
double getsalary() const;
void setSalary (double newsalary);
void printCheck();
protected:
double salary;
};//weekly
}//savitchEmployees
//SALARIEDEMPLOYEE_H
#endif
//salariedemployee.cpp
#include<iostream>
#include<string>
#include"SalariedEmployee.h"
using std::string;
using std::cout;
using std::endl;
namespace SavitchEmployees
{
SalariedEmployee::SalariedEmployee():Employee(),salary(0)
{//deliberatel empty
}
SalariedEmployee::SalariedEmployee(const string& newName, const string& newNumber, double newWeeklyPay)
{
//deliberaely empty
}
double SalariedEmployee::getsalary() const
{
return salary;
}
void SalariedEmployee::setSalary(double newSalary)
{
salary=newSalary;
}
void SalariedEmployee::printCheck()
{
setNetPay(salary);
cout<<" _____________________________________ ";
cout<<"Pay to the order of "<<getName()<<endl;
cout<<"The sum of "<<getNetPay()<<"Dollars ";
cout<<" _____________________________________ ";
cout<<"Check Stub Not Negotiable ";
cout<<"Employee Number"<<getSsn()<<endl;
cout<<"Salaried Employee. Regular Pay"<<salary<<endl;
cout<<" _____________________________________ ";
}
}
//Administrator.h
#ifndef PROTECT_ADMINISTRATOR_H
#define PROTECT_ADMINISTRATOR_H
#include "SalariedEmployee.h"
#include "employee.h"
#include <iostream>
namespace SavitchEmployees
{
class Administrator : public SalariedEmployee
{
public:
//Constructors:
Administrator();
Administrator(string admName,string admSSn,string admTitle,string admResponsibilty,string admSupervisor,double admSalary);
void changeSupervisor(string admSuper);
// Reads a new administrator's data from the keyboard
void getAdminData();
//outputs administrator's data to the screen
void print();
// prints a check with appropriate notations on the check
void printCheck();
void giveRaise(double admamount);
protected:
string admtitle; // administrator's title
// (CEO, Director, Vice President)
string admresponsibility; // such as production,
// accounting, personnel
string admsupervisor; // name of immediate supervisor
double admannualSalary; // if not added in the self test exercise
};
} // end this segment of namespace SavitchEmployees
#endif
//Administrator.cpp
//Administrator.cpp
#include "employee.h"
#include "Administrator.h"
#include <iostream>
namespace SavitchEmployees
{
void Administrator::giveRaise(double admamount)
{
admannualSalary += admamount;
}
Administrator:: Administrator() : SalariedEmployee()
{
}
Administrator:: Administrator(string admName, string admSSn, string admTitle, string admResponsibilty, string admSupervisor, double admSalary): SalariedEmployee(admName, admSSn, 0.0),
admtitle(admTitle),admresponsibility(admResponsibilty),admsupervisor( admSupervisor), admannualSalary(admSalary)
{
//deliberately empty
}
// change name of immediate supervisor
void Administrator::changeSupervisor(string admSuper)
{
admsupervisor = admSuper;
}
// Reading all of a new administrator's data from the keyboard.
void Administrator::getAdminData()
{
using namespace std;
char n[80];
cout << " Administrative Employee data is being entered: ";
cout << "Enter the Administrator's name : ";
cin.getline(n, 80);
setName(n);
cout << "Enter social security number : ";
cin.getline(n, 80);
ssn = n;
cout << "Enter a title : ";
cin.getline(n, 80);
admtitle = n;
cout << " Enter an area of responsibility : ";
cin.getline(n, 80);
admresponsibility = n;
cout << " Enter the name of employee's supervisor : ";
cin.getline(n, 80);
admsupervisor = n;
cout << " Enter salary : ";
cin >> admannualSalary;
}
//outputs administrator's data to the screen
void Administrator::print()
{
using namespace std;
cout << " printing Administrator data ";
cout << "Name: " << getName() << endl;
cout << "Annual Salary: $" << admannualSalary << endl;
cout << "Social Security Number: " << ssn << endl;
cout << "Title: ";
cout << admtitle << endl;
cout << "Responsibility:";
cout << admresponsibility << endl;
cout << "supervisor: ";
cout << admsupervisor << endl;
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout.precision(2);
cout << "Annual Salary: "
<< admannualSalary << endl << endl;
}
// prints a check with appropriate notations on the check
void Administrator::printCheck()
{
using namespace std;
double monthlyPay = admannualSalary/12;
cout << " ________________________________________________ ";
cout << "Pay to the order of " << name << endl << endl;
cout.setf(ios::showpoint);
cout.setf(ios::fixed);
cout.precision(2);
cout << "The sum of $" << monthlyPay << " Dollars ";
cout << " _________________________________________________ ";
cout << "Check Stub NOT NEGOTIABLE ";
cout << "Employee Number: " << ssn << endl << endl;
cout << "Administrative Employee. ";
cout << "_________________________________________________ ";
}
}// end this segment namespace SavitchEmployees
//main.cpp
//main.cpp
#include <iostream>
#include <stdlib.h>
#include "Administrator.h"
using namespace std;
using namespace SavitchEmployees;
int main()
{
Administrator admin1;
admin1.getAdminData();
admin1.print();
system("pause");
return 0;
}
Result:
Administrative Employee data is being entered:
Enter the Administrator's name :
Abav
Enter social security number :
123456
Enter a title :
Doctor
Enter an area of responsibility :
Acountability
Enter the name of employee's supervisor :
Esbwn
Enter salary :
987896
printing Administrator data
Name: Abav
Annual Salary: $987896
Social Security Number: 123456
Title: Doctor
Responsibility:Acountability
supervisor: Esbwn
Annual Salary: 987896.00
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.