C++ Employee Class CS 1410 – Beginning the Employee Series Project Background Th
ID: 3804490 • Letter: C
Question
C++ Employee Class
CS 1410 – Beginning the Employee Series Project
Background
This program is the first of a series of three programs that will you will do over the course of the semester that deal with a payroll application. When you are done with this project, be sure to put it in a safe place because you will use it later. Modern software development is very much an incremental and iterative process. Programs are developed a piece at a time as their developers iterate on the design, refactor existing code, and add new function. This set of exercises will give you a glimpse into that process. In this first program you will develop an Employee class and test it with a simple driver program. This project is all about properly designing and coding a program that uses a class of your own design and that is easy to modify.
Objectives:
1. Refine your object oriented design skills.
2. Give you practice drawing a class diagram.
3. Create the proper structure and code for a C++ program containing a class of your design.
4. Create a driver program to test your class.
The Employee Class
For this project you need to design an Employee class. Your Employee class should have the following data members:
employeeNumber (integer)
name (string)
street address (string)
phone number (string)
hourly wage (double)
hours worked this week (double)
Your Employee class will have the following functions:
A constructor for the Employee class that takes arguments to initialize all of the above mentioned data members.
Getters for each attribute of your class.
Setters that follow encapsulation principles for each class attributes except the employee number which never changes.
A function, calcPay( ) that calculates and returns an employee's net pay. An employee's gross pay is calculated by multiplying the hours worked by their hourly wage. Be sure to give time-and-a-half for overtime (anything over 40 hours). To compute the net pay, deduct 20% of the gross for Federal income tax, and 7.5% of the gross for state income tax.
Before you write any code, create a class diagram for this class. You will include your class diagram when you submit this assignment.
The Driver
The major function of the driver is to test your Employee class. By no means is it a complete, polished application. Such a driver is common when doing iterative development. In this project, you will create a .cpp file that contains your driver code and a stand-alone printCheck( ) function.
The printCheck( ) function is not a member of any class. It will output the employee's name, the employee's net pay for this pay period, the hours worked by the employee, and their hourly wage. The function should output these in a rough simulation of a paycheck and paystub, as illustrated in the sample output below.
Your driver will contain a main( ) function that does the following. You may use this description as your pseudo-code:
1. Create an Employee object for an employee whose hourly wage is $10.00, and who has worked 45 hours. Use your imagination to come up with your employee's name and other employee information.
2. Create a second employee object for an employee whose hourly wage is $12.50 and who has worked 30 hours.
3. Call your printCheck( ) function, passing the first Employee object as the argument.
Submitting Your Assignment
After you are satisfied that your program works correctly, submit it to Canvas in accordance with course standards. Note check to make sure you included:
1. The source code for your driver.
2. The source code for the Employee .h and .cpp files.
3. A screen shot of your execution results.
4. A class diagram pdf.
CM Users 10002705 DesktopWcode projo4Debuglproj04.exe Fluff Shuffle Electronics Pay to the order of Joe Brown $344.38 United Bank of Eastern orem Hours worked 45.00 Hourly Wage 10.00 Press any key to continueExplanation / Answer
//Employee.h Header file
#include<iostream>
using namespace std;
//Employee class definition
class Employee
{
//Data member
private:
int employeeNumber;
string name;
string streetAddress;
string phoneNumber;
double hourlyWage;
double hoursWorkedThisWeek;
public:
//Parameterized constructor to initialize data member
Employee(int en, string nm, string sa, string pn, double hw, double hww)
{
employeeNumber = en;
name = nm;
streetAddress = sa;
phoneNumber = pn;
hourlyWage = hw;
hoursWorkedThisWeek = hww;
}//End of constructor
//Returns Employee Number
int getEmployeeNumber()
{
return employeeNumber;
}//End of function
//Returns employee name
string getName()
{
return name;
}//End of function
//Returns street address
string getStreetAddress()
{
return streetAddress;
}//end of function
//Returns phone number
string getPhoneNumber()
{
return phoneNumber;
}//End of function
//Returns Hourly Wage
double gethourlyWage()
{
return hourlyWage;
}//End of function
//Returns Hours Worked this week
double gethoursWorkedThisWeek()
{
return hoursWorkedThisWeek;
}//End of function
//Sets Employee Name
void setName(string na)
{
name = na;
}//End of function
//Sets Street Address
void setStreetAddress(string sa)
{
streetAddress = sa;
}//End of function
//Sets Phone Number
void setPhoneNumber(string pn)
{
phoneNumber = pn;
}//End of function
//Sets Hourly Wage
void sethourlyWage(double hw)
{
hourlyWage = hw;
}//End of function
//Sets Hours Worked This Week
void sethoursWorkedThisWeek(double hww)
{
hoursWorkedThisWeek = hww;
}//End of function
//Calculates and returns net payment
double calcPay()
{
double diff, gross, net, federalIncomeTax, stateIncomeTax;
diff = gross = net = federalIncomeTax = stateIncomeTax = 0;
//Checks for greater than 40 hours
if(hoursWorkedThisWeek > 40)
gross = (((hoursWorkedThisWeek - 40.0)/2.0) * hourlyWage) + (hourlyWage * (hoursWorkedThisWeek - diff));
else
gross = hoursWorkedThisWeek * hourlyWage;
//Calculates Federal Income Tax
federalIncomeTax = gross * (20.0/100);
//Calculates State Income Tax
stateIncomeTax = gross * (7.5/100);
//Calculates net payment
net = gross - (federalIncomeTax + stateIncomeTax);
//returns net payment
return net;
}//End of function
};//End of class
//Employee.cpp file
#include "Employee.h"
#include <iostream>
#include <conio.h>
using namespace std;
//Function takes class object and displays Employees net payment information
void printCheck(Employee ee)
{
cout<<" --------------------- Fluff Shuffle Electronics -------------------------------- ";
cout<<" Pay to the order of "<<ee.getName()<<"..........................."<<ee.calcPay();
cout<<" United Bank of Eastern Orem ";
cout<<"------------------------------------------------------------------------------- ";
cout<<" Hours Worked: "<<ee.gethoursWorkedThisWeek();
cout<<" Hourly Wage: "<<ee.gethourlyWage();
}//End of function
//Main function
int main()
{
//Creates two objects by calling parameterized constructor
Employee emp1(111, "Rakesh", "BAM", "1234556785", 10.00, 45.00);
Employee emp2(222, "Suresh", "BBSR", "8835556788", 12.50, 30.00);
//Calls function to displays information
printCheck(emp1);
cout<<" Press any key to continue..........";
getch();
printCheck(emp2);
}//End of main
Output:
--------------------- Fluff Shuffle Electronics --------------------------------
Pay to the order of Rakesh...........................344.375
United Bank of Eastern Orem
-------------------------------------------------------------------------------
Hours Worked: 45
Hourly Wage: 10
Press any key to continue..........
--------------------- Fluff Shuffle Electronics --------------------------------
Pay to the order of Suresh...........................271.875
United Bank of Eastern Orem
-------------------------------------------------------------------------------
Hours Worked: 30
Hourly Wage: 12.5
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.