Question: My code needs to include average netpay and I belive that is all that it is missing. so the output needs to display the average
My code needs to include average netpay and I belive that is all that it is missing. so the output needs to display the average netpay and that seems to be the only missing component, using DEVC++ compiler.
MY code
#include
#include
#include
#include
using namespace std;
class payroll{
ifstream fin;
string employeeid;
string employeename;
char maritalstatus;
int hoursworked, overtime;
double hourlyrate, overtimepay, regularpay, grosspay, taxrate, taxamount,netpay;
void calculategrosspay();
void calculatetax();
void calculatenetpay();
void printheadings();
void printdata();
public:
payroll();
~payroll();
void printreport();
};
payroll::payroll(){
fin.open("payroll.dat");
}//CONSTRUCTOR
payroll::~payroll(){
fin.close();
}//DESTRUCTOR
void payroll::calculategrosspay(){
overtime = overtimepay =0;
if(hoursworked>40){
overtime=hoursworked-40;
hoursworked = hoursworked - overtime; //it will be 40
regularpay=hoursworked*hourlyrate;
overtimepay=overtime*(hourlyrate*1.5);
grosspay=regularpay+overtimepay;
}//F
else
grosspay=hoursworked*hourlyrate;
}//CALCULATEGROSSPAY
void payroll::calculatetax(){
if(grosspay>=500)
taxrate=.30;
else if(grosspay>200)
taxrate=.20;
else
taxrate=.10;
if(maritalstatus=='S')
taxrate=taxrate+.05;
taxamount=grosspay*taxrate;
}//CALCULATETAX
void payroll::calculatenetpay(){
netpay=grosspay-taxamount;
}//CALCULATENETPAY
void payroll::printheadings(){
cout< cout<<"__________________________________"< cout<<"\tNAME \tEMPLOYEEID HOURSWORKED OVERTIME REGULARPAY OVERTIMEPAY GROSS TAX NETPAY"< cout<<"__________________________________"< }//PRINTHEADINGS void payroll::printdata(){ cout< cout< < < < < < < < < }//PRINTDATA void payroll::printreport(){ int i=0, idx; printheadings(); char line[256]; string str; while(fin.getline(line, 256)){ //extract employeeid str = string(line); idx = str.find("-"); employeeid = str.substr(idx+1); //extract employeename fin.getline(line, 256); str = string(line); idx = str.find("-"); employeename = str.substr(idx+1); //extract maritalstatus fin.getline(line, 256); str = string(line); idx = str.find("-"); maritalstatus = str[idx+1]; //extract just 1 character //extract hoursworked fin.getline(line, 256); str = string(line); idx = str.find("-"); hoursworked = atoi(str.substr(idx+1).c_str()); //extract hourlyrate fin.getline(line, 256); str = string(line); idx = str.find("-"); hourlyrate = atof(str.substr(idx+1).c_str()); calculategrosspay(); calculatetax(); calculatenetpay(); printdata(); i++; }//WHILE }//PRINTREPORT int main(){ payroll employee; employee.printreport() ;//MAIN return 0; } and my payroll.dat is EMPLOYEE ID-481756 NAME-BONITA KOWALSKI MARITALSTATUS-SINGLE HOURS WORKED-43 HOURLYRATE-12 EMPLOYEE ID-481755 NAME-WALT KOWALSKI MARITALSTATUS-MARRIED HOURS WORKED-12 HOURLYRATE-10 EMPLOYEE ID-481754 NAME-CHARLES XAVIER MARITALSTATUS-SINGLE HOURS WORKED-41 HOURLYRATE-15 EMPLOYEEID-481753 NAME-LOGAN WOLF MARITALSTATUS-Married HOURS WORKED-10 HOURLYRATE-9 EMPLOYEEID-481752 NAME-STORM RAIN MARITAL STATUS-Single HOURSWORKED-27 HOURLYRATE-10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
