trouble with inheritance(inital problem solved)
Aug 9, 2008 at 10:17pm UTC
I know its been a while since I had a problem, but this chapter has been kicking my butt. I got the program to compile. The data for fist printreport is fine. The data for the second one is is coming out wrong. It appeares to add all of the salary and spitting it out as the same for each data in the second part. Also none of the calculation looks to be no being processed. Anyone Please, give a nudge in the right direction. Your help is appreciated.
Also on line 54, I want to / yearsal by 52 to get gp but when I write yearsal/52=gp I get a lvaule error if that helps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
//declaration of variables
class payroll{
public : int id, hw, oth;
float hr, otp, rgp, gp, tax, np, TAXR;
char fname[15], lname[15], ms;
void findovt();
void findgp();
void findtaxr();
void findtax();
void findnp();
void headings();
void outputall();
payroll();
~payroll();
void printreport(); };//STRUCT
class salary: public payroll{
public : float yearsal;
void yearsalgp();
salary();
~salary();
void printreport(); };
payroll::payroll(){
ifstream fin("payrollfl.txt" );}
payroll::~payroll(){
ifstream fin();}
salary::salary(){
ifstream fin("sal.txt" );}
salary::~salary(){
ifstream fin();}
void payroll::findovt(){
if (hw>40){
oth=hw-40;
otp=oth*hr*1.5;
rgp=hw*hr;
}//IF
else {
oth=0;
otp=0;
rgp=hw*hr;
}//ELSE
}//FINDOVT
void salary::yearsalgp(){
yearsal=gp;
oth=0;
otp=0;
}
void payroll::findgp(){
gp=rgp+otp;
}//FINDGP
void payroll::findtaxr(){
if ((gp>1000) && (ms=='S' ||ms=='s' )) TAXR=0.35;
else if ((gp>1000) && (ms=='M' ||ms=='m' )) TAXR=0.30;
else if ((gp>1000) && (ms=='H' ||ms=='h' )) TAXR=0.25;
else if ((gp>800) && (ms=='S' ||ms=='s' )) TAXR=0.25;
else if ((gp>800) && (ms=='M' ||ms=='m' )) TAXR=0.20;
else if ((gp>800) && (ms=='H' ||ms=='H' )) TAXR=0.15;
else if ((gp>500) && (ms=='S' ||ms=='s' )) TAXR=0.15;
else if ((gp>500) && (ms=='M' ||ms=='m' )) TAXR=0.10;
else if ((gp>500) && (ms=='H' ||ms=='h' )) TAXR=0.05;
else TAXR=0.0;
}//FINDTAXR
void payroll::findtax(){
tax=gp*TAXR;
}//FINDTAX
void payroll::findnp(){
np=gp-tax;
}//FINDNP
void payroll::headings(){
cout<<setiosflags(ios::left)<<" Digdug's National Bank" <<endl<<endl;
cout<<setiosflags(ios::left)<<setw(15)<<"FIRST NAME" <<setw(15)<<"LAST NAME" <<setw(7)<<"EMP ID" <<setw(4)<<"HW" <<setw(6)<<"HR" <<setw(5)<<"STAT" <<setw(5)<<"OTH" <<setw(7)<<"OTP" <<setw(7)<<"REGP" <<setw(9)<<"GROSS" <<setw(7)<<"TAX" <<setw(7)<<"NET" <<endl<<endl;
cout<<setiosflags(ios::left)<<setw(15)<<"==============" <<setw(15)<<"==============" <<setw(7)<<"======" <<setw(4)<<"===" <<setw(6)<<"=====" <<setw(5)<<"====" <<setw(5)<<"===" <<setw(7)<<"======" <<setw(7)<<"======" <<setw(9)<<"========" <<setw(7)<<"======" <<setw(7)<<"======" <<endl;
}
void payroll::outputall(){
cout<<fixed;
cout<<setiosflags(ios::showpoint|ios::fixed|ios::left)<<setw(15)<<fname
<<setw(15)<<lname<<setw(7)<<id<<setw(4)<<setprecision(1)<<hw
<<setw(6)<<setprecision(2)<<hr<<setw(5)<<ms<<setw(5)
<<setprecision(1)<<oth<<setw(7)<<setprecision(2)<<otp<<setw(9)
<<rgp<<setw(9)<<gp<<setw(7)<<tax<<setw(7)<<np<<endl;
}//OUTPUTALL
void payroll::printreport(){
int i=0;
float sumnp=0;
float avgnp;
headings();
ifstream fin("payrollfl.txt" );
while (fin>>fname>>lname>>id>>hw>>hr>>ms){
findovt();
findgp();
findtaxr();
findtax();
findnp();
outputall();
i++;
sumnp=sumnp+np; }
avgnp=sumnp/i;
cout<<"THE AVERAGE NETPAY IS: " <<avgnp<<endl;
}
void salary::printreport(){
int j=0;
float sumnp=0;
float avgnp;
ifstream fin("sal.txt" );
while (fin>>fname>>lname>>id>>yearsal>>ms){
yearsalgp();
findtaxr();
findtax();
findnp();
outputall();
j++;
sumnp=sumnp+np; }
avgnp=sumnp/j;
cout<<"THE AVERAGE NETPAY IS: " <<avgnp<<endl;
}
//main function
int main(void ){
payroll employee;
employee.printreport();
system("pause" );
}//MAIN
// function definitions
//end
Last edited on Aug 10, 2008 at 3:10am UTC
Aug 10, 2008 at 3:13am UTC
Believe it or not I solved the issue but not sure if that was right way of doing it. All I know was it works now. Here is the code I changed to make it work please somebody let me know if this was the right way or if there is a better way.
1 2 3 4 5 6 7 8
void salary::yearsalgp(){
hw=40;
hr=(yearsal/52)/40;
rgp=hr*40;
gp=rgp+otp;
oth=0;
otp=0;
}
Now that I have what isee as the hard step time to make it better.
Topic archived. No new replies allowed.