Question

In: Computer Science

The objective of this homework is to give you experience using inheritance with C++. You will...

The objective of this homework is to give you experience using inheritance with C++. You will use the provided employee base class and implement two derived classes, salaried employee and hourly employee.

For this assignment, you will use the base class Employee, which is implemented with the files Employee.h and Employee.cpp. A test file, test.cpp, is also provided for your use, as you choose to use it.

Each employee object has a user id; a first and last name; a middle initial; and a department code (integer). Your implementation must now add two derived classes. The first one will be for a salaried employee, which will require a monthly salary variable. You will need member functions including a constructor, set and get salary functions, a salary calculation function, and a print function. For versatility, you might include a variable that specifies what fraction of time the person worked and use the fraction in the salary calculation. Hint: set the fraction default to one. For consistency, name your salaried employee class as SalariedEmployee

Your second class should represent an hourly worker. In this case you will need to store the hours worked and the hourly rate. You should also include provisions for overtime hours, which will be paid at 1.5 times the regular hourly rate. Hint: set the default overtime hours to 0. You will need similar functions as the salaried employee to set and get variables, as well as to calculate salary. Name your hourly employee class as HourlyEmployee.

Generate a test file that includes at least two of each type of worker to test the classes for proper operation. I recommend a full-time and half-time salaried worker and two hourly worker test cases, one of which earns overtime.

Execute your test program and copy the outputs to a text file to demonstrate proper execution.

/* employee.cpp*/


#include <iostream>
#include <iomanip>


#include <string>


#include "Employee.h"

using namespace std;

// constructor

Employee::Employee(long id, const string &last, const string &first, const string &initial,
           int dept)
{
myIdNum = id;
myLastName = last;
myFirstName = first;
myMiddleInitial = initial;
myDeptCode = dept;
}

// Accessor function defintions

void Employee::setIdNum (const long id)
{
myIdNum = id;
}

long Employee:: getIdNum () const               // get id number
{
return myIdNum;
}


void Employee:: setLastName (const string &last)   // set last name
{
myLastName = last;
}


string Employee:: getLastName () const           // return last name
{
return myLastName;
}


void Employee:: setFirstName (const string &first)   // set first name
{
myFirstName = first;
}


string Employee:: getFirstName () const           // return first name
{
return myFirstName;
}


void Employee:: setMiddleInitial (const string &last)   // set middle initial
{
myMiddleInitial = last;
}


string Employee:: getMiddleInitial () const       // return middle initial
{
return myMiddleInitial;
}


void Employee::setDeptCode (const int dc)       // set department code
{
myDeptCode = dc;
}


int Employee:: getDeptCode () const               // get department code
{
return myDeptCode;
}


void Employee:: printEmployee ()           // print Employee information
{
cout << endl;
cout << "Employee ID Number: " << getIdNum() << endl;
cout << "Name: " << getLastName() <<", " << getFirstName() << " " <<
       getMiddleInitial() <<"." << endl;
cout << "Dept Code: " << getDeptCode () << endl;
}

/* employee.h   */

#ifndef EMPLOYEE
#define EMPLOYEE

#include <string>

using namespace std;

class Employee
{
public:
Employee(long = 0, const string & ="" , const string & ="", const string & = "", int =0);   // constructor

void setIdNum (const long );           // set id number
long getIdNum () const;               // get id number
void setLastName (const string &);   // set last name
string getLastName () const;           // return last name
void setFirstName (const string &);   // set first name
string getFirstName () const;           // return first name
void setMiddleInitial (const string &);   // set middle initial
string getMiddleInitial () const;       // return set middle initial
void setDeptCode(const int);           // set department code
int getDeptCode () const;               // get department code
void printEmployee ();               // print Employee information



private:
long myIdNum;           //Employee id number
string myLastName;       //Employee last name
string myFirstName;       //Employee first name
string myMiddleInitial;   //Employee middle intial
int myDeptCode;           //Department code
};

#endif

/* File: test.cpp */
// File to test the basic employee class

#include<iostream>
#include <string>
#include "Employee.h"

using namespace std;

int main()
{
Employee
e1 (001, "Jones", "Booker", "T", 22),
e2 (002, "Hendrix", "Jimi", "NMI ", 14),
e3 (003, "Morrison", "Jim", "D", 03);

e1.printEmployee();
e2.printEmployee();

}

Solutions

Expert Solution

#include <iostream>
#include <iomanip>


#include <string>


#include "Employee.h"

using namespace std;

// constructor

Employee::Employee(long id, const string &last, const string &first, const string &initial,
           int dept)
{
myIdNum = id;
myLastName = last;
myFirstName = first;
myMiddleInitial = initial;
myDeptCode = dept;
}

// Accessor function defintions

void Employee::setIdNum (const long id)
{
myIdNum = id;
}

long Employee:: getIdNum () const               // get id number
{
return myIdNum;
}


void Employee:: setLastName (const string &last)   // set last name
{
myLastName = last;
}


string Employee:: getLastName () const           // return last name
{
return myLastName;
}


void Employee:: setFirstName (const string &first)   // set first name
{
myFirstName = first;
}


string Employee:: getFirstName () const           // return first name
{
return myFirstName;
}


void Employee:: setMiddleInitial (const string &last)   // set middle initial
{
myMiddleInitial = last;
}


string Employee:: getMiddleInitial () const       // return middle initial
{
return myMiddleInitial;
}


void Employee::setDeptCode (const int dc)       // set department code
{
myDeptCode = dc;
}


int Employee:: getDeptCode () const               // get department code
{
return myDeptCode;
}


void Employee:: printEmployee ()           // print Employee information
{
cout << endl;
cout << "Employee ID Number: " << getIdNum() << endl;
cout << "Name: " << getLastName() <<", " << getFirstName() << " " <<
       getMiddleInitial() <<"." << endl;
cout << "Dept Code: " << getDeptCode () << endl;
}


Related Solutions

This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
The objective of this homework assignment is to demonstrate proficiency with reading files, and using string...
The objective of this homework assignment is to demonstrate proficiency with reading files, and using string methods to slice strings, working with dictionaries and using-step wise development to complete your program. Python is an excellent tool for reading text files and parsing (i.e. filtering) the data. Your assignment is to write a Python program in four steps that reads a Linux authentication log file, identifies the user names used in failed password attempts and counts the times each user name...
Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create...
Please do this in C++ Objective: Create an Inheritance Hierarchy to Demonstrate Polymorphic Behavior 1. Create a Rectangle 2. Class Derive a Square Class from the Rectangle Class 3. Derive a Right Triangle Class from the Rectangle Class 4. Create a Circle Class 5. Create a Sphere Class 6. Create a Prism Class 7. Define any other classes necessary to implement a solution 8. Define a Program Driver Class for Demonstration (Create a Container to hold objects of the types...
Write a program in C A teacher will assign homework and give the number of days...
Write a program in C A teacher will assign homework and give the number of days for the students to work on. The student is responsible for calculating the due date. The teacher does not collect homework on Friday or weekend. Write a C program that let the user enter today’s day of the week (0 for Sunday, 1 for Monday, etc.) and the number of days to allow the students to do the work, which may be several weeks....
Question Objective: The objective of this lab exercise is to give you practice in programming with...
Question Objective: The objective of this lab exercise is to give you practice in programming with one of Python’s most widely used “container” data types -- the List (commonly called an “Array” in most other programming languages). More specifically you will demonstrate how to: Declare list objects Access a list for storing (i.e., writing) into a cell (a.k.a., element or component) and retrieving (i.e., reading) a value from a list cell/element/component Iterate through a list looking for specific values using...
Objective The objective of this lab exercise will be for the student to gain experience conducting...
Objective The objective of this lab exercise will be for the student to gain experience conducting a wireless networking site survey. The objective is for each group to propose a wireless networking solution for a given space (such as a classroom, office rooms, home, etc.). Verify that you can establish link (by pinging) with another laptop in your network. (Also, you may demonstrate this by downloading the shared file on another computer in the same network). Required Each individual/group will...
Overview and objective: Basic logic In this homework, you will exercise your understanding of boolean logic...
Overview and objective: Basic logic In this homework, you will exercise your understanding of boolean logic and the gates and circuits that embody it. A thorough understanding of boolean logic is extremely useful for almost all programming tasks and necessary to correctly implement complex systems. Additionally, greater familiarity with boolean logic should improve one’s ability to think critically in general as it forms the basis for all human reasoning. Technical Description and Instructions: 1. Consider the logical expression ( !x...
explain the principle of the inheritance give an example( CS related) of class inheritance
explain the principle of the inheritance give an example( CS related) of class inheritance
c++ using polymorphyism , create an inheritance hierarchy for the following types of insurance : Home,...
c++ using polymorphyism , create an inheritance hierarchy for the following types of insurance : Home, vehicle , life 2 member functions should be included: - calcpremium    - Home- 0.5% of the value of the home    - Life- 1% of the value of the policy    - Vehicle - 0.5% of the value of the policy calcCommission Home- 0.2% of the value of the home Life- 1% of the value of the policy Vehicle - 0.5% of the...
In C++ Please, using only the libraries given in this homework prompt, Write a program that...
In C++ Please, using only the libraries given in this homework prompt, Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT