#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
ifstream fin;
char employeeid[12];
char employeename[20];
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("employee.txt"); }//CONSTRUCTOR
payroll::~payroll(){
fin.close(); }//DESTRUCTOR
void payroll:: calculategrosspay(){
if(hoursworked>40){
overtime=hoursworked-40;
regularpay=hoursworked*hourlyrate;
overtimepay=overtime*(hourlyrate*1.5);
grosspay=regularpay+overtimepay; }//IF
else grosspay=hoursworked*hourlyrate; }//CALCULATEGROSSPAY
void payroll::calculatetax(){
if(grosspay>=500) taxrate=.30;
else if(grosspay>200.00) taxrate=.20;
else taxrate=.10;
if(maritalstatus=='S'||maritalstatus=='s')
taxrate=taxrate+.05;
taxamount=grosspay*taxrate; }//CALCULATETAXRATE
void payroll::calculatenetpay(){
netpay=grosspay-taxamount; }//CALCULATENETPAY
void payroll::printheadings(){
cout<<setw(45)<<"-PAYROLL REPORT-"<<endl;
cout<<"--------------------------------------------------------------------"<<endl;
cout<<"NAME ID HW OT RT-PAY OT-PAY GROSS"
" TAX NETPAY"<<endl;
cout<<"--------------------------------------------------------------------"<<endl;
}//PRINTHEADINGS
void payroll::printdata(){
cout<<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)
<<hoursworked<<setw(3)<<overtime<<setw(8)<<regularpay<<setw(8)
<<overtimepay<<setw(8)<<grosspay<<setw(8)<<taxamount<<setw(8)
<<netpay<<endl; }//PRINTDATA
void payroll::printreport(){
int i=0;
printheadings();
while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate){
calculategrosspay();
calculatetax();
calculatenetpay();
printdata();
i++; }//WHILE
}//PRINTREPORT
main(){
payroll employee;
employee.printreport();
system("PAUSE");
}//MAIN
Now this is what my average netpay looked like in my original payroll program:
for(i; i<n; i++){
totalNetPay +=netpay[i];
cout<<""<<id[i]<<"\t"<<hoursworked[i]<<"\t"<<hourlyrate[i]
<<"\t"<<overtimepay[i]<<"\t\t"<<grosspay[i]<<"\t\t"
<<taxamount[i]<<"\t"<<netpay[i]<<endl;
}//FOR
cout<<"The net pay average of the employees are: "<<totalNetPay/i<<endl;
Now how would this look if I wanted to convert it to run properly in the new program I created with an employee class? Or what steps would I need to take? Classes are brand new to me and the only thing teaching me all of this is a book. Sometimes it helps to speak to somebody who may be able to explain it better. Thank you.

New Topic/Question
Reply



MultiQuote





|