EBK PROBLEM SOLVING WITH C++
EBK PROBLEM SOLVING WITH C++
9th Edition
ISBN: 9780133834505
Author: SAVITCH
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 15, Problem 1P

Write a program that uses the class SalariedEmployee in Display 15.5. Your program is to define a 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 did the change recommended earlier.

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.

An overloading of the member function printCheck() with appropriate notations on the check.

Expert Solution & Answer
Check Mark
Program Plan Intro

Salaried Employee

Program Plan:

administrator.h:

  • Include required header files.
  • Create a namespace.
    • Declare a class “Administrator”.
      • Inside the “protected” access specifier,
        • Declare a variable to hold the salary amount.
      • Inside the “public” access specifier,
        • Declare the constructors.
        • Declare the member functions.
      • Inside the “private” access specifier,
        • Declare the variables to store the title, responsibility, and name of the supervisor.

administrator.cpp:

  • Include required header files.
  • Create a namespace.
    • Declare constructors.
    • Set the supervisor name.
    • Give function definition for “readData ()”.
      • Get the title, responsibility and supervisor name from the user.
    • Give function definition for “print ()”.
      • Print the details like name, responsibility and supervisor name.
    • Give function definition for “printCheck ()”.
      • Call the function “setNetPay ()” to set the amount.
      • Print the name using the function “getName ()”.
      • Print the amount using the function “getNetPay ()”.
      • Print the employee number using the function “getSSN ()”.

salariedemployee.h:

  • Include required header files.
  • Create a namespace.
    • Declare a class “SalariedEmployee”.
      • Inside “public” access specifier,
        • Declare default and parameterized constructor.
        • Declare the function “getSalary ()”, and “setSalary ()”.
      • Inside “protected” access specifier,
        • Declare a variable “salary”.

salariedemployee.cpp:

  • Include required header files.
  • Create a namespace.
    • Instantiate the constructors.
    • Give mutator and accessor functions to set and get the salary amount respectively.

employee.h:

  • Include required header files.
  • Create a namespace.
    • Inside the “public” access specifier.
      • Declare the default and parameterized constructor.
      • Declare the functions.
    • Inside the “private” access specifier.
      • Declare required variables like “name”, “ssn”, and “netPay”.

employee.cpp:

  • Include required header files.
  • Create a namespace.
    • Instantiate the constructors.
    • Give mutator and accessor functions to set and get the name, employee number, and net pay.
    • Give function to print the check.

main.cpp:

  • Include required header files.
  • Declare the “main ()” function.
    • Create an object for “Administrator” class.
    • Call the function “readData ()”, “print ()”, and “printCheck ()” using the object.
Program Description Answer

The below program demonstrates the creation of “Administrator” class with the required given constraints.

Explanation of Solution

Program:

administrator.h:

//Include required header files

#ifndef ADMINISTRATOR_H

#define ADMINISTRATOR_H

#include <string>

#include "salariedemployee.h"

using namespace std;

//Create a namespace

namespace SEmployees

{

    //Declare a class

    class Administrator : public SalariedEmployee

    {

        //Access specifier

        protected:

            //Declare a variable

            double theAnnualSalary;

        //Access specifier

        public:

            //Constructors

            Administrator();

     Administrator(const string& theName, const string& theSsn, double theAnnualSalary);

            //Declare the member functions

     void setSupervisor(const string& newSupervisorName);

            void readData();

            void print();

            void printCheck();

        //Access specifier

        private:

            //Declare required variables

            string adminTitle;

            string areaOfResponsibility;

            string supervisorName;

    };

}

#endif

administrator.cpp:

//Include required header files

#include <string>

#include <iostream>

#include "administrator.h"

using namespace std;

//Create a namespace

namespace SEmployees

{

    //Constructor

  Administrator::Administrator() : SalariedEmployee(), adminTitle("No title yet"),areaOfResponsibility("No responsibility yet"), supervisorName("No supervisor yet"){}

    //Constructor

  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"){}

    //Function to set supervisor name

  void Administrator::setSupervisor(const string& newSupervisorName)

    {

        //Set the name

        supervisorName = newSupervisorName;

    }

    //Function to get the information

    void Administrator::readData()

    {

        //Print the statement

     cout << "Enter the details of the administrator " << getName() << endl;

        //Ge the title

        cout << " Enter the administrator's title: ";

        getline(cin, adminTitle);

        //Get the area of responsibility

     cout << " Enter the company area of responsibility: ";

        getline(cin, areaOfResponsibility);

        //Get the name of supervisor

     cout << " Enter the name of this administrator's immediate supervisor: ";

        getline(cin, supervisorName);

    }

    //Function to print information

    void Administrator::print()

    {

        //Print the statement

     cout << "\nDetails of the administrator..." << endl;

        //Print the name

     cout << "Administrator's name: " << getName() << endl;

        //Print the title

     cout << "Administrator's title: " << adminTitle << endl;

        //Print the responsibility

     cout << "Area of responsibility: " << areaOfResponsibility << endl;

        //Print the supervisor name

     cout << "Immediate supervisor's name: " << supervisorName << endl;       

    }

    //Function to print the check

    void Administrator::printCheck()

    {

        //Print the statement

        cout << "\nPay check..." << endl;

        //Call the function

        setNetPay(salary);

        //Print the statements

     cout << "\n_______________________________________________\n";

        //Print the name

     cout << "Pay to the order of " << getName() << endl;

        //Print the amount

        cout << "The sum of $" << getNetPay();

     cout << "\n_______________________________________________\n";

        cout << "Check Stub NOT NEGOTIABLE \n";

        //Print the employee number

     cout << "Employee Number: " << getSSN() << endl;

        //Print the salary

     cout << "Salaried Employee (Administrator). Regular Pay: $" << salary;

     cout << "\n_______________________________________________\n";

    }

}

salariedemployee.h:

//Include required header files

#ifndef SALARIEDEMPLOYEE_H

#define SALARIEDEMPLOYEE_H

#include <string>

#include "employee.h"

using namespace std;

//Create a namespace

namespace SEmployees

{

    //Declare a class

    class SalariedEmployee : public Employee

    {

        //Access specifier

        public:

        //Default constructor

        SalariedEmployee( );

        //Parameterized constructor

     SalariedEmployee (string theName, string theSSN,double theWeeklySalary);

        //Function declarations

        double getSalary( ) const;

        void setSalary(double newSalary);

        //Access specifier

        protected:

        //Declare a variable

        double salary;

    };

}

#endif

salariedemployee.cpp:

//Include required header files

#include <iostream>

#include <string>

#include "salariedemployee.h"

using namespace std;

//Create a namespace

namespace SEmployees

{

    //Constructors

  SalariedEmployee::SalariedEmployee( ) : Employee( ), salary(0){}

  SalariedEmployee::SalariedEmployee(string theName, string theNumber,double theWeeklySalary): Employee(theName, theNumber), salary(theWeeklySalary){}

    //Accessor function to get the salary

    double SalariedEmployee::getSalary( ) const

    {

        //Return the amount

    return salary;

    }

    //Mutator function to set the salary

    void SalariedEmployee::setSalary(double newSalary)

    {

        //Set the amount

    salary = newSalary;

    }

}

employee.h:

//Include required header files

#ifndef EMPLOYEE_H

#define EMPLOYEE_H

#include <string>

using namespace std;

//Create a namespace

namespace SEmployees

{

    //Declare a class

    class Employee

    {

        //Access specifier

        public:

        //Declare a default constructor

        Employee( );

        //Declare the parameterized constructor

        Employee(string theName, string theSSN);

        //Declare the functions

        string getName( ) const;

        string getSSN( ) const;

        double getNetPay( ) const;

        void setName(string newName);

        void setSSN(string newSSN);

        void setNetPay(double newNetPay);

        void printCheck( ) const;

        //Access specifier

        private:

            //Declare required variables

        string name;

        string ssn;

        double netPay;

    };

}

#endif

employee.cpp:

//Include required header files

#include <string>

#include <cstdlib>

#include <iostream>

#include "employee.h"

using namespace std;

//Create a namespace

namespace SEmployees

{

    //Constructors

  Employee::Employee( ) : name("No name yet"), ssn("No number yet"), netPay(0){}

  Employee::Employee(string theName, string theNumber): name(theName), ssn(theNumber), netPay(0){}

    //Accessor function to get a name

    string Employee::getName( ) const

    {

        //Return the name

        return name;

    }

    //Accessor function to get the number

    string Employee::getSSN( ) const

    {

        //Return the number

        return ssn;

    }

    //Accessor function to get the pay

    double Employee::getNetPay( ) const

    {

        //Return the pay

        return netPay;

    }

    //Mutator function to set the name

    void Employee::setName(string newName)

    {

        //Set the name

        name = newName;

    }

    //Mutator function to set the number

    void Employee::setSSN(string newSSN)

    {

        //Set the number

        ssn = newSSN;

    }

    //Mutator function to set the pay

    void Employee::setNetPay (double newNetPay)

    {

        //Set the pay

        netPay = newNetPay;

    }

    //Function to print the check

    void Employee::printCheck() const

    {

        //Print the statements.

     cout << "\nERROR: printCheck FUNCTION CALLED FOR AN \n"<< "UNDIFFERENTIATED EMPLOYEE. Aborting the program.\n"<< "Check with the author of the program about this bug.\n";

        exit(1);

    }

}

main.cpp:

//Include required header files

#include <iostream>

#include "administrator.h"

//Create namespace

using SEmployees::Administrator;

//Main function

int main()

{

    //Add details

  Administrator admin("Mr. John Smith", "963-85-2741", 10000.00);

    //Call the function to read information

    admin.readData();

    //Call the function to print

    admin.print();

    //Call the function to print the check

    admin.printCheck();

    //Return the statement

    return 0;

}

Sample Output

Output:

Enter the details of the administrator Mr. John Smith

 Enter the administrator's title:  Director

 Enter the company area of responsibility:  Personnel

 Enter the name of this administrator's immediate supervisor:  Mr. Adams

Details of the administrator...

Administrator's name: Mr. John Smith

Administrator's title: Director

Area of responsibility: Personnel

Immediate supervisor's name: Mr. Adams

Pay check...

_______________________________________________

Pay to the order of Mr. John Smith

The sum of $10000

_______________________________________________

Check Stub NOT NEGOTIABLE

Employee Number: 963-85-2741

Salaried Employee (Administrator). Regular Pay: $10000

_______________________________________________

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Previous Exercise to help with answering the question which is below | Write the header file (.h file) of a class Counter containing: A data member counter of type int. A data member named counterID of type int. A static int data member named nCounters. A constructor that takes an int argument. A function called increment that accepts no parameters and returns no value. A function called decrement that accepts no parameters and returns no value. A function called getValue that accepts no parameters and returns an int. A function named getCounterID that accepts no parameters and returns an int.   #include<iostream>using namespace std; class Counter{private:int counter;int counterID;static int nCounters;public:Counter(int c);void increment();void decrement();int getValue();int getCounterID();}; ----------------------------------------------------------------------- ANSWER THIS QUESTION!In C++ Write the implementation (.cpp file) of the Counter class of the previous exercise.The…
Write a program to model a student class with roll number and name as the sensitive information. Initialize default values for the sensitive information using a default constructor, use a copy constructor to copy from another object, use a member function to take user input and update the name and roll number and display the same using another member function.   b.Add constructor overloading to the above code and enable initialization of name, roll number via constructor arguments.   NAME ROHI ROLLNO 18
Build a class Pet having the following data membersa. Name (String)b. Gender (char)c. Type (String)d. Age (int)e. Weight (float)f. healthCondition (int)Imagine this class Pet represents your pet as a virtualobject. Provide constructors with arguments for name,gender, type, age and weight. Initialize healthCondition to 5(which means healthy). Provide getter for each of these but setter for only weight. Provide a function eat(String food). This function represents the action of eating thatwould increase the weight of the pet according to following rulesFood Increase In WeightRed Meat 0.14 kgChicken 0.12 kgPet Food 0.17 kgSupplement 0.1 kgFish 0.09 kgThe eat function returns the new Weight of the pet object.Provide another function fallSick() that reduces the healthCondition of the pet 1 but it cannot gobelow 0. Provide a function bool isDead() this function returns true if the healthCondition of a pet is 0and false otherwise. Add another function recover(). This function increases…

Chapter 15 Solutions

EBK PROBLEM SOLVING WITH C++

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY