R
Randi
Hi,
Looking for some help with this payrool project I have for class. This is
what the instructor asks for so far. I have it working without errors but
am getting some funky numbers. I am not sure if they would be correct
anyways. Below is the instructions.
and below that is what I have. Any tips or hints would be highly
appreciated.
Regards,
Kelsey
You have been hired to write a program that will perform payroll tasks. The
program must be written using object-orientated programming concepts. This
implies that you MUST use the C++ class structure in this program. This
payroll program will contain an Employee class to store the employee's name,
hourly rate, hours worked, gross pay, and net pay. The class should have
operations that will perform the following tasks.
1. An operation to initialize the hourly rate to a minimum wage of
$5.50 per hour and the hours worked to 0 when the employee is defined.
2. An operation to obtain the employee's name, hourly rate, and hours
worked from the user.
3. An operation to return the weekly gross pay, including overtime pay,
where overtime is paid at the rate of time-and-a-half for any hours worked
over 40.
4. An operation to return the weekly net pay, based on a 30% deduction
for taxes and benefits.
5. An operation to display the employee's name, gross pay, and net pay.
Your program should demonstrate that it works by allowing the user to run
the program and enter in an employee's name, pay rate, and hours. Then
output the name, net pay and gross pay to the screen.
My Crappy code..
#include<iostream>
#include<iomanip>
#include <string>
using namespace std;
class Employee
{
private:
string name;
float hourlyrate;
float hoursworked;
float gp;
float np;
float otpay;
public:
Employee();
Employee(string empName, float hoursW, float rate);
void getinfo();
float grosspay();
float overtime();
float netpay();
void display();
};
Employee:: Employee()
{
name = " ";
hourlyrate =0;
hoursworked =0;
}
Employee::Employee(string n, float hw, float hr)
{
name = n;
hoursworked = hw;
hourlyrate= hr;
}
void Employee:: getinfo()
{
cout<<"Enter the emplyees name"<<endl;
cin>>name;
cout<<"Enter the hours worked"<<endl;
cin>>hoursworked;
cout<<"Enter the hourly rate"<<endl;
cin>>hourlyrate;
}
float Employee::grosspay()
{
float gp =0;
gp = hoursworked * hourlyrate;
return gp;
}
float Employee:vertime()
{
float ot=0;
float otpay=0;
if(hoursworked>40)
{
ot=hoursworked-40;
otpay = ot*1.5;
return otpay;
}
}
float Employee::netpay()
{
float np =0;
np = (otpay + gp)*.70;
return np;
}
void Employee::display()
{
cout<<name<<" "<<gp<<" "<<np<<endl;
}
void main()
{
float gp =0;
float otpay =0;
float np =0;
Employee book(" ",0,5.5);
book.getinfo();
gp = book.grosspay();
otpay = book.overtime();
np = book.netpay();
book.display();
}
Looking for some help with this payrool project I have for class. This is
what the instructor asks for so far. I have it working without errors but
am getting some funky numbers. I am not sure if they would be correct
anyways. Below is the instructions.
and below that is what I have. Any tips or hints would be highly
appreciated.
Regards,
Kelsey
You have been hired to write a program that will perform payroll tasks. The
program must be written using object-orientated programming concepts. This
implies that you MUST use the C++ class structure in this program. This
payroll program will contain an Employee class to store the employee's name,
hourly rate, hours worked, gross pay, and net pay. The class should have
operations that will perform the following tasks.
1. An operation to initialize the hourly rate to a minimum wage of
$5.50 per hour and the hours worked to 0 when the employee is defined.
2. An operation to obtain the employee's name, hourly rate, and hours
worked from the user.
3. An operation to return the weekly gross pay, including overtime pay,
where overtime is paid at the rate of time-and-a-half for any hours worked
over 40.
4. An operation to return the weekly net pay, based on a 30% deduction
for taxes and benefits.
5. An operation to display the employee's name, gross pay, and net pay.
Your program should demonstrate that it works by allowing the user to run
the program and enter in an employee's name, pay rate, and hours. Then
output the name, net pay and gross pay to the screen.
My Crappy code..
#include<iostream>
#include<iomanip>
#include <string>
using namespace std;
class Employee
{
private:
string name;
float hourlyrate;
float hoursworked;
float gp;
float np;
float otpay;
public:
Employee();
Employee(string empName, float hoursW, float rate);
void getinfo();
float grosspay();
float overtime();
float netpay();
void display();
};
Employee:: Employee()
{
name = " ";
hourlyrate =0;
hoursworked =0;
}
Employee::Employee(string n, float hw, float hr)
{
name = n;
hoursworked = hw;
hourlyrate= hr;
}
void Employee:: getinfo()
{
cout<<"Enter the emplyees name"<<endl;
cin>>name;
cout<<"Enter the hours worked"<<endl;
cin>>hoursworked;
cout<<"Enter the hourly rate"<<endl;
cin>>hourlyrate;
}
float Employee::grosspay()
{
float gp =0;
gp = hoursworked * hourlyrate;
return gp;
}
float Employee:vertime()
{
float ot=0;
float otpay=0;
if(hoursworked>40)
{
ot=hoursworked-40;
otpay = ot*1.5;
return otpay;
}
}
float Employee::netpay()
{
float np =0;
np = (otpay + gp)*.70;
return np;
}
void Employee::display()
{
cout<<name<<" "<<gp<<" "<<np<<endl;
}
void main()
{
float gp =0;
float otpay =0;
float np =0;
Employee book(" ",0,5.5);
book.getinfo();
gp = book.grosspay();
otpay = book.overtime();
np = book.netpay();
book.display();
}