Concept explainers
Write a
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.
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.
- Inside the “protected” access specifier,
- Declare a class “Administrator”.
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”.
- Inside “public” access specifier,
- Declare a class “SalariedEmployee”.
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”.
- Inside the “public” access specifier.
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.
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;
}
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?
Chapter 15 Solutions
Problem Solving with C++ (9th Edition)
Additional Engineering Textbook Solutions
C++ How to Program (10th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
C How to Program (8th Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
- Write a class Runner having three private data members (distance, minutes, seconds) The class has A constructor which having no parameter – for setting values to zero or null.Getters/setters for data members.Write a function show() which displays the“The player covered “+distance+ “ in “ +minutes +” minutes , and “ + seconds+” seconds”; Write test Application that demonstrates the above class by calling all the methods, creating a Create 3 Runner objects, input values and then display the record of winner.in javaarrow_forwardWrite a class Runner having three private data members (distance, minutes, seconds) The class has A constructor which having no parameter – for setting values to zero or null.Getters/setters for data members.Write a function show() which displays the“The player covered “+distance+ “ in “ +minutes +” minutes , and “ + seconds+” seconds”; Write test Application that demonstrates the above class by calling all the methods, creating a Create 3 Runner objects, input values and then display the record of winner.arrow_forwardQ#: Write a class Email that contain the following fields, which other classes may not access: To From Subject Content Write a function member called SendEmail that initialize all the class fields through information passing as parameters. SendEmail method will print the content of email only. Write a driver class with any name that must have a main method. Inside main, call SendEmail.arrow_forward
- Problem: Create a Fraction class with two private positive integer member variables numerator and denominator, one constructor with two integer parameters num and den with default values 0 and 1, one display function that print out a fraction in the format numerator/denominator in the proper form such as 2/3 or ½ . Note: 2/4 should be displayed as ½.arrow_forwardCreate a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the class—the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. Provide public member functions that perform each of the following tasks: Adding two Rational numbers. The result should be stored in reduced Subtracting two Rational numbers. The result should be stored in reduced Multiplying two Rational numbers. The result should be stored in reduced Dividing two Rational numbers. The result should be stored in reduced Printing Rational numbers in the form a/b, where a is the numerator and b is the denominator. Printing Rational numbers in floating-pointformatarrow_forwardWrite a program that declares two classes. The parent class is called Simple that has two data members’ num1 and num2 to store two numbers. It also has four member functions.· The add() function adds two numbers anddisplays the result.· The sub() function subtracts two numbersand displays the result.· The mul() function multiplies twonumbers and displays the result.The div() function divides two numbersand displays the result. The child class is called Complex that overrides all four functions. Each function in the child class checks the value of data members. It calls the corresponding member function in the parent class if the values are greater than 0. Otherwiseit displays error message.arrow_forward
- Create a class named ElectricCar and display its model, color, mpg and condition. Note that ElectricCar is a class which inherits from its parent class named Car. In the parent class Car, it has a global variable named condition and its condition is set to ”new” at all time, and has three variables in the constructor ”model, color and mpg”. Furthermore, in the parent class Car, it contains two functions a display car function that displays the car attributes (such as model, color and mpg) and a drive car function that changes the condition to ”used”. Moreover, in the child ElectricCar class, it has one more attribute ”battery type” and it overrides the drive car function by setting the condition to ”like new”. To test your class CreateaElectricCarnamedmyCarbysettingmodel=”DeLorean”,color=”silver”, mpg=88, and battery type=”molten salt”. Display myCar’s condition by ”print(myCar.condition)”. Output is ”new”. Change myCar’s condition to ”like new” by myCar.drive car(). Again,…arrow_forwardIN C++ Lab #6: Shapes Create a class named Point. private attributes x and y of integer type. Create a class named Shape. private attributes: Point points[6] int howManyPoints; Create a Main Menu: Add a Triangle shape Add a Rectangle shape Add a Pentagon shape Add a Hexagon shape Exit All class functions should be well defined in the scope of this lab. Use operator overloading for the array in Shape class. Once you ask the points of any shape it will display in the terminal the points added.arrow_forwardCreate a class called Complex for performing arithmetic with complex numbers. Write a program to test your class. Complex numbers have the form realPart + imaginaryPart * i where i is Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided. Provide public member functions that perform the following tasks: a) Adding two Complex numbers: The real parts are added together and the imaginary parts are added together. b) Subtracting two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand, and the imaginary part of the right operand is subtracted from the imaginary part of the left operand. c) Printing Complex numbers in the form (a, b)., where a is the real part and b is the imaginary part. #include #include "Complex.h" using namespace std; int main() {…arrow_forward
- In C++ create a program that acts like a bank account. It asks the user whether to deposit or withdraw. That has 3 classes. The first class must be a generic class that holds basic info deposit, withdraw, calculate monthly interest rate, and a monthly service fee.The second class must be a savings account class that if the savings account falls below $25 it becomes inactive. The final class must be a checking account if someone withdraws more than what they have a service charge of $15 is added and go into a negative balance. The output should display the basic information how much someone deposited or withdrew and their monthly interest rate.arrow_forwardCreate two classes named Mammals and MarineAnimals. Create another class named BlueWhale which inherits both the above classes. Now, create a function in each of these classes which prints "I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as well as Marine Animals" respectively. Now, create an object for each of the above class and try calling function of Mammals by the object of Mammal function of BlueWhale by the object of BlueWhale function of each of its parent by the object of BlueWhale function of MarineAnimal by the object of MarineAnimalarrow_forward4. Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four data members-a part number (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (type int). Your dlass should have a constructor that initializes the four data members. A constructor that receives multiple arguments is defined with the form: ClassName( TypeName1 parameterName1, TypeName2 parameterName2, .) Provide a set and a get function for each data member. In addition, provide a member function named getinvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as an int value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a class program according to the main.cpp program given below. #include #include invoice #include…arrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,