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
SURVEY OF OPERATING SYSTEMS
Starting Out With Visual Basic (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- what type of internet connection should be avoided on mobile devices?arrow_forwardI need help creating the network diagram and then revising it for the modified activity times.arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward
- Given the following Extended-BNF grammar of the basic mathematical expressions: Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGEarrow_forwardWhentheuserenters!!,themostrecentcommandinthehistoryisexecuted.In the example above, if the user entered the command: Osh> !! The ‘ls -l’ command should be executed and echoed on user’s screen. The command should also be placed in the history buffer as the next command. Whentheuserentersasingle!followedbyanintegerN,theNthcommandin the history is executed. In the example above, if the user entered the command: Osh> ! 3 The ‘ps’ command should be executed and echoed on the user’s screen. The command should also be placed in the history buffer as the next command. Error handling: The program should also manage basic error handling. For example, if there are no commands in the history, entering !! should result in a message “No commands in history.” Also, if there is no command corresponding to the number entered with the single !, the program should output "No such command in history."arrow_forwardActivity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.arrow_forward
- 2. UNIX Shell and History Feature [20 points] This question consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt osh> and the user's next command: cat prog.c. The UNIX/Linux cat command displays the contents of the file prog.c on the terminal using the UNIX/Linux cat command and your program needs to do the same. osh> cat prog.c The above can be achieved by running your shell interface as a parent process. Every time a command is entered, you create a child process by using fork(), which then executes the user's command using one of the system calls in the exec() family (as described in Chapter 3). A C program that provides the general operations of a command-line shell can be seen below. #include #include #define MAX LINE 80 /* The maximum length command */ { int…arrow_forwardQuestion#2: Design and implement a Java program using Abstract Factory and Singleton design patterns. The program displays date and time in one of the following two formats: Format 1: Date: MM/DD/YYYY Time: HH:MM:SS Format 2: Date: DD-MM-YYYY Time: SS,MM,HH The following is how the program works. In the beginning, the program asks the user what display format that she wants. Then the program continuously asks the user to give one of the following commands, and performs the corresponding task. Note that the program gets the current date and time from the system clock (use the appropriate Java date and time operations for this). 'd' display current date 't': display current time 'q': quit the program. • In the program, there should be 2 product hierarchies: "DateObject” and “TimeObject”. Each hierarchy should have format and format2 described above. • Implement the factories as singletons. • Run your code and attach screenshots of the results. • Draw a UML class diagram for the program.arrow_forward#include <linux/module.h> #include <linux/kernel.h> // part 2 #include <linux/sched.h> // part 2 extra #include <linux/hash.h> #include <linux/gcd.h> #include <asm/param.h> #include <linux/jiffies.h> void print_init_PCB(void) { printk(KERN_INFO "init_task pid:%d\n", init_task.pid); printk(KERN_INFO "init_task state:%lu\n", init_task.state); printk(KERN_INFO "init_task flags:%d\n", init_task.flags); printk(KERN_INFO "init_task runtime priority:%d\n", init_task.rt_priority); printk(KERN_INFO "init_task process policy:%d\n", init_task.policy); printk(KERN_INFO "init_task task group id:%d\n", init_task.tgid); } /* This function is called when the module is loaded. */ int simple_init(void) { printk(KERN_INFO "Loading Module\n"); print_init_PCB(); printk(KERN_INFO "Golden Ration Prime = %lu\n", GOLDEN_RATIO_PRIME); printk(KERN_INFO "HZ = %d\n", HZ); printk(KERN_INFO "enter jiffies = %lu\n", jiffies); return 0; } /* This function is called when the…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,
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT