SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

ABSOLUTE C++

Absolute C++

Authors:
Walter Savitch ,kenrick Mock
Exercise:
Programming Projects
Chapter:
Inheritance
Edition:
5
ISBN:
9780132846813
Question:
1

 

Question

Write a program that uses the class SalariedEmployee given in Display 14.4. Your program is to define a derived class called Administrator , which is to be derived from the class SalariedEmployee . You are allowed to change private in the base class to protected . You are to supply the following additional data and function members:

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

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

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

■ A protected member variable of type double that holds the administrator’s annual salary. It is possible for you to use the existing salary member if you changed private in the base class to protected.

■ A member function called setSupervisor , which changes the supervisor name.

■ A member function for reading in an administrator’s data from the keyboard.

■ A member function called print , which outputs the object’s data to the screen.

■ Finally, an overloading of the member function printCheck( ) with appropriate notations on the check.



Answer

Complete Program:

NOTE: Please change private in the base class (SalariedEmployee) to protected.
Please refer the textbook for salariedemployee.h, salariedemployee.cpp, employee.h, and employee.cpp files

// File adminstrator.h

#ifndef ADMINISTRATOR_H
#define ADMINISTRATOR_H
#include <string>
#include "salariedemployee.h"
using std::string;
namespace SavitchEmployees
{
	class Administrator : public SalariedEmployee
	{
	public:
		Administrator();
		Administrator(const string& theName, const string& theSsn, double theAnnualSalary);
		void setSupervisor(const string& newSupervisorName);
		void readData();
		void print();
		void printCheck();
		
	private:
		string adminTitle; 
		string areaOfResponsibility;
		string supervisorName;
	};
}
#endif
// File adminstrator.cpp

#include <string>
#include <iostream>
#include "administrator.h"
using std::string;
using std::cout;
using std::endl;
using std::cin;
namespace SavitchEmployees
{
	Administrator::Administrator() 
              : SalariedEmployee(), adminTitle("No title yet"), 
                areaOfResponsibility("No responsibility yet"), 
                supervisorName("No supervisor yet")
	{
		//deliberately empty
	}

	Administrator::Administrator(const string& theName, const string& theSsn, 
                                       double theAnnualSalary)
                : SalariedEmployee(theName, theSsn, theAnnualSalary), 
                  adminTitle("No title yet"), areaOfResponsibility("No responsibility yet"), 
                  supervisorName("No supervisor yet")
	{
		//deliberately empty
	}

  	void Administrator::setSupervisor(const string& newSupervisorName)
	{
		supervisorName = newSupervisorName;
	}

	void Administrator::readData()
	{
		cout << "Enter the details of the administrator " << getName() << endl;
		cout << " Enter the administrator's title: ";
		getline(cin, adminTitle);
		cout << " Enter the company area of responsibility: ";
		getline(cin, areaOfResponsibility);
		cout << " Enter the name of this administrator's immediate supervisor: ";
		getline(cin, supervisorName);
	}

	void Administrator::print()
	{
		cout << "\nDetails of the administrator..." << endl;
		cout << "Administrator's name: " << getName() << endl;
		cout << "Administrator's title: " << adminTitle << endl;
		cout << "Area of responsibility: " << areaOfResponsibility << endl;
		cout << "Immediate supervisor's name: " << supervisorName << endl;		
	}

	void Administrator::printCheck()
	{
		cout << "\nPay check..." << endl;
		setNetPay(salary);
		cout << "\n_______________________________________________\n";
		cout << "Pay to the order of " << getName() << endl;
		cout << "The sum of $" << getNetPay();
		cout << "\n_______________________________________________\n";
		cout << "Check Stub NOT NEGOTIABLE \n";
		cout << "Employee Number: " << getSsn() << endl;
		cout << "Salaried Employee (Administrator). Regular Pay: $" << salary;
		cout << "\n_______________________________________________\n";
	}
}
// File: main.cpp

#include <iostream>
#include "administrator.h"
using SavitchEmployees::Administrator;
int main()
{
	Administrator admin("Mr. John Smith", "963-85-2741", 10000.00);

	admin.readData();

	admin.print();
	 
	admin.printCheck();

	return 0;
}

Sample Output:

0 0

Discussions

Post the discussion to improve the above solution.