Question: this is assignment i am working on they are two projects the first one i have done and the specifications on the first are listed
this is assignment i am working on they are two projects the first one i have done and the specifications on the first are listed then we have to modify the first project which i added the paramteres below the first I am not going to lie i am completely lost on this and any direction would be appreciated.
Project 1 parameters
Background
This program is the first of a series of three programs that 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 a copy 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 functionality. This set of exercises will give you a glimpse into that process. In this first program you will develop an Employee class. This project is all about properly designing and coding a program that uses a class of your own design that is easy to modify.
Objective
Develop object-oriented design skills.
Create the proper structure and code for a C++ program containing a class of your design.
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)
address (string)
phone (string)
hourlyWage (double)
hoursWorked 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 data attribute of your class.
Setters for every attribute except employeeNumber. We will not use the setters in this assignment, but in an actual payroll application, employee data, except for the employee number, can change (due to address change, marriage, a raise or promotion etc.).
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.
A function, printCheck() that prints out a pay check for each employee.
The major function of this first exercise is to test your Employee class. You will upload 3 files:
employee.h
employee.cpp
main.cpp
Your main() function does the following.
Creates two Employee objects with data that you can glean from the output below. These objects will be 'hard coded' into your .cpp file. There will be no interactive input for this program.
Calls the needed getter member functions to display the employee's name, number, address, and phone, as shown below.
Calls printCheck() to print the check, which follows the employee's personal information. Note that printCheck calls calcPay, and prints the whitespace that you see below before and after the check portion.
Project 2 paramters
Background
Recall that we are iterating on the development of a payroll program. At this point, you should have a working Employee class. In this project you will add the ability for objects of your Employee class to write themselves out to a file, and be read in from a file. The ability for an object to save itself in a file is called persistence.
You will also throw an exception if there are any file I/O errors. Get your program working without exception handling first. Then add the exception handling.
Objectives
Continue to refine your object oriented design skills.
Create the proper structure and code for a C++ program containing a class of your design.
Create a class that has persistence.
Throw and handle an exception.
Create a main() function to test the additions to your class.
The Employee Class
For this project you need to add the following member functions to your Employee class.
Employee read(ifstream&) void write(ofstream&)
The function Employee::read is a static member function. It returns an Employee object based on the data it reads from a file. It must be called as Employee::read(...) since it's job is to create an object. If there is a read error, it throws a std::runtime_error (defined in
The main() function
The major goal of main() is to test the additions to your Employee class. Use the printCheck() function from your previous Employee project. The output of your program will look similar to the output of your previous Employee project.
Your driver will contain a main() function that does the following:
Present the user with a menu of choices, create a data file, or read data from a file and print checks:
This program has two options: 1 - Create a data file, or 2 - Read data from a file and print paychecks. Please enter <1> to create a file or <2> to print checks:
If the user selects the first option, your program should:
Create an ofstream object using a file name obtained from the user. Pass just the file name as the parameter (no path) so that your program assumes the file to be in the same folder as your executable file.
Create three employee objects as shown:
Employee joe(37, "Joe Brown", "123 Main St.", "123-6788", 45.00, 10.00)
Employee sam(21, "Sam Jones", "45 East State", "661-9000", 30.00, 12.00)
Employee mary(15, "Mary Smith", "12 High Street", "401-8900", 40.00, 15.00)
Send messages to each of the three Employee objects to write themselves out to the file.
Print a message that creation of the file is complete.
Exit.
If the user selects the second option, your program should:
Prompt for the name of the file that the program saved.
Call Employee::read to read in the objects written in step 1, one-by-one.
Call the printCheck() function for each of the three new objects, just as you did in the previous project.
Exit.
Run the second option twice. Once with the correct filename, and once with an incorrect one. The second run will test your exception handling. In the error case, throw a std::runtime_error (defined in
In addition, when reading the file for the second part, you need to check that the expected data is there. If there are any errors in the data (there shouldn't be, but you should check anyway), your code should throw a std::runtime_error with a message explaining which data was corrupted.
my code
.h file
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include
using namespace std;
class employee {
public:
void SetEmployeeNumber(int num);
void SetName(string eName), SetPhone(string phoneNum), SetAddress(string addressNum);
void SetHourlyWage(), SetHoursWorked();
void Print() const;
void PrintCheck(double hoursWorked, double hourlyWage);
double calcPay(double hoursWorked, double hourlyWage);
double netIncome(double federalTax, double stateTax);
private:
int employeeNumber;
string name, phone, address;
double hourlyWage, hoursWorked/*,federalTax, stateTax, moneyz*/;
};
#endif
.cpp file
#include "employee.h"
#include
#include
using namespace std;
int employeeNumber;
string name;
string address;
string phone;
double hourlyWage;
double hoursWorked;
double PayCheck;
double gross;
double lilBro;
double bigBro;
void employee::SetEmployeeNumber(int num)
{
employeeNumber = num;
return;
}
void employee::SetName(string eName)
{
name = eName;
return;
}
void employee::SetPhone(string phoneNum)
{
phone = phoneNum;
return;
}
void employee::SetAddress(string addressNum)
{
address = addressNum;
return;
}
void employee::SetHourlyWage()
{
}
void employee::SetHoursWorked()
{
}
void employee::Print() const
{
cout << "Employee Name: " << name << endl;
cout << "Employee Number: " << employeeNumber << endl;
cout << "Address: " << address << endl;
cout << "Phone: " << phone << endl;
cout << ' ';
cout << endl;
cout << endl;
return;
}
//Calculates the amount of their paycheck and returns
double employee::calcPay(double hoursWorked, double hourlyWage)
{
if (hoursWorked > 40)
{
gross = ((hoursWorked - 40) * (hourlyWage * 1.5)) + (40 * hourlyWage);
}
else
{
gross = hourlyWage * hoursWorked;
}
return gross;
}
void employee::PrintCheck(double hoursWorked, double hourlyWage)
{
calcPay(hoursWorked, hourlyWage);
cout << fixed << showpoint << setprecision(2);
cout << "Hours worked: " << hoursWorked << " Hourly wage: " << hourlyWage << endl;
}
main
#include
#include
using namespace std;
#include "employee.h"
int main() {
employee person1;
person1.SetName("Joe Brown");
person1.SetEmployeeNumber(37);
person1.SetAddress("123 Main St.");
person1.SetPhone("123-6788");
person1.Print();
double gross1 = person1.calcPay(45, 10);
double myMoney = gross1 - (gross1 *.2 ) - (gross1 *.075);
cout << "....................UVU Computer Science Dept................................."<< endl;
cout << "Pay to the order of Joe Brown...................................." << "$" << fixed << showpoint << setprecision(2) << myMoney << endl;
cout << "United Community Credit Union" < cout << ".............................................................................."<< endl; person1.calcPay(45, 10); person1.PrintCheck(45, 10); employee person2; person2.SetName("Sam Jones"); person2.SetEmployeeNumber(37); person2.SetAddress("45 East State"); person2.SetPhone("661-9000"); person2.Print(); double gross2 = person2.calcPay(30, 12.50); double myMoney1 = gross2 - (gross2 *.2 ) - (gross2 *.075); cout << "....................UVU Computer Science Dept................................."<< endl; cout << "Pay to the order of Sam Jones...................................."<< "$" << fixed << showpoint << setprecision(2) << myMoney1 << endl; cout << "United Community Credit Union" < cout << ".............................................................................."<< endl; person2.calcPay(30, 12.50); person2.PrintCheck(30, 12.50); return 0;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
