Need some help with this assignment, I keep getting id returned 1 exit status for my code and cannot get it to work any
Posted: Tue Jul 12, 2022 8:21 am
Need some help with this assignment, I keep getting id returned1 exit status for my code and cannot get it to work anysuggestions?
Program 2 - sort netpay (regular sort-exchange or selection)Sort the net pays (salary). For now, display only the net paysbefore sorting and after sorting.
Program 3 - Sort the netpay by thepointersSort the net pays (salary) using an array of pointers (do notchange the data in the original array). For now, display only thenet pays before sorting Sort the net pays (salary) using an arrayof pointers (do not change the data in the original array). Fornow, display only the net pays before sorting and aftersorting.
#include<iostream>#include<fstream>#include<iomanip>
using namespace std;
//function prototypes
int readalldata(longint[],char[],string[],string[],int[],double[],const int);void computeotp(int[],int[],double[],double[],int);voidcomputegp(double[],int[],double[],double[],double[],int);void computetaxrate(double[],double[],int);void computemtaxrate(char[],double[],double[],int);voidcomputenetpay(double[],double[],double[],double[],double[],int);double computesum(double[],int);double computeavg(double,int);void sortnetpay(double[],int);void displayarrays(longint[],char[],string[],string[],int[],double[],int[],double[],double[],double[],double[],double[],float,double,double[],int);
int main(){const int MAXSIZE = 100; int n;long int employeeid[MAXSIZE];char marital[MAXSIZE];string firstname[MAXSIZE], lastname[MAXSIZE];double hourlyrate[MAXSIZE], grosspay[MAXSIZE], netpay[MAXSIZE],taxrate[MAXSIZE], mtaxrate[MAXSIZE], taxamount[MAXSIZE],regpay[MAXSIZE], otpay[MAXSIZE];double sum;double avg;
int hoursworked[MAXSIZE], othours[MAXSIZE];
//FUCNTION CALLS
n =readalldata(employeeid,marital,firstname,lastname,hoursworked,hourlyrate,MAXSIZE); computeotp(hoursworked,othours,hourlyrate,otpay,n);computegp(grosspay,hoursworked,hourlyrate,otpay,regpay,n);computetaxrate(grosspay,taxrate,n);computemtaxrate(marital,mtaxrate,taxrate,n);computenetpay(taxamount,grosspay,taxrate,mtaxrate,netpay,n);sum=computesum(netpay,n);avg=computeavg(sum,n);sortnetpay(netpay,n);displayarrays(employeeid,marital,firstname,lastname,hoursworked,hourlyrate,othours,otpay,regpay,grosspay,taxamount,netpay,sum,avg,netpay,n);return 0;}//end of main function
//FUCNTION DEFINITIONSint readalldata(long int employeeid[],char marital[],stringfirstname[],string lastname[],int hoursworked[],doublehourlyrate[],int n){ifstream fin("payroll3.txt");n = 0;while(fin>>employeeid[n]>>marital[n]>>firstname[n]>>lastname[n]>>hoursworked[n]>>hourlyrate[n]){n++;}//while
fin.close();return n;}//readall
void computeotp(int hoursworked[],int othours[],doublehourlyrate[],double otpay[],int n){ for(int i = 0;i < n;i++){ if (hoursworked >= 40) othours =hoursworked - 40; otpay = othours * hourlyrate * 1.5;
if (hoursworked < 40) otpay =0; else othours = 0;}//if}//OTPAY
void computegp(double grosspay[],int hoursworked[],doublehourlyrate[],double otpay[],double regpay[],int n){ for(int i = 0;i < n;i++){ grosspay =(hoursworked[i] * hourlyrate[i]) +otpay[i]; regpay[i] = (grosspay[i] -otpay[i]); }//for}//GROSSPAY
void computetaxrate(double grosspay[],double taxrate[],intn){ for(int i = 0;i < n;i++){ if(grosspay[i] > 4000) taxrate[i] =0.40; else if(grosspay[i] > 3000) taxrate[i] =0.30; else if(grosspay[i] > 1000) taxrate[i] =0.20; else taxrate[i] = 0.10;}//for}//TAXRATE
void computemtaxrate(char marital[],double mtaxrate[],doubletaxrate[],int n){ for(int i = 0;i < n;i++){ if(marital[i] == 'S' || marital[i] == 's')mtaxrate[i] += 0.05; else if(marital[i] == 'H' || marital[i] == 'h')mtaxrate[i] -= 0.05; else taxrate[i];}//for}//MTAXRATE
void computenetpay(double taxamount[],double grosspay[],doubletaxrate[],double mtaxrate[],double netpay[],int n){ for(int i = 0;i < n;i++){ taxamount[i] = (grosspay[i] * (taxrate[i] +mtaxrate[i])); netpay[i] = grosspay[i] - taxamount[i];}//for}//NETPAYdouble computesum(double netpay[], int n){ double sum=0; for(int i = 0;i < n; i++){ sum=sum+netpay[i];
}//for return sum;}//SUM
double computeavg(double sum, int n){ double avg; for(int i=0; i<n; i++){ avg=sum/n; }//for return avg;}//AVG
void sortnetpay(double netpay[],int n){for(int i=0;i<n-1;i++) for(int j=0;j<n-i-1;j++) if(netpay[j]>netpay[j+1]){ float temp=netpay[j]; netpay[j]=netpay[j+1]; netpay[j+1]=temp;}}
void displayarrays(long int employeeid[],char marital[],stringfirstname[],string lastname[],int hoursworked[],doublehourlyrate[],int othours[],double otpay[],double regpay[],double grosspay[],double taxamount[],double netpay[],floatsum,double avg, int n){
cout<<" DR. EBRAHIMI'S PAYROLL INSTITUTE"<<endl;cout<<endl;cout<<endl;cout<<setw(15),setprecision(1),setiosflags(ios::fixed|ios::showpoint|ios::left);cout<<"EMP ID"<<setw(14)<<"MARTIALSTAT"<<setw(12)<<"FIRSTNAME"<<setw(12)<<"LAST NAME"<<setw(6)<<"HW"<<setw(6)<<"HR"<<setw(6)<<"OTP"<<setw(6)<<"REGP"<<setw(7)<<"GROSS"<<setw(10)<<"TAX"<<setw(10)<<"NET"<<endl;cout<<endl;for(int i = 0;i < n;i++){cout<<setw(15),setprecision(1),setiosflags(ios::fixed|ios::showpoint|ios::left);cout<<employeeid[i]<<setw(14)<<marital[i]<<setw(12)<<firstname[i]<<setw(12)<<lastname[i]<<setw(6)<<hoursworked[i]<<setw(6)<<hourlyrate[i]<<setw(6)<<otpay[i]<<setw(6)<<regpay[i]<<setw(7)<<grosspay[i]<<setw(10)<<taxamount[i]<<setw(10)<<netpay[i]<<endl;}//for
cout<<endl;cout<<"SUM OF EMPLOYEE NETPAY IS:$"<<sum<<endl;cout<<"AVERAGE OF NETPAY OF EMPLOYEES IS:$"<<avg<<endl;for(int i = 0;i < n;i++){cout<<"NETPAY BEFORE SORTING :"<<netpay[i]<<endl;cout<<"NETPAY AFTER SORTING :"<<netpay[i]<<endl;}
}//display
Program 2 - sort netpay (regular sort-exchange or selection)Sort the net pays (salary). For now, display only the net paysbefore sorting and after sorting.
Program 3 - Sort the netpay by thepointersSort the net pays (salary) using an array of pointers (do notchange the data in the original array). For now, display only thenet pays before sorting Sort the net pays (salary) using an arrayof pointers (do not change the data in the original array). Fornow, display only the net pays before sorting and aftersorting.
#include<iostream>#include<fstream>#include<iomanip>
using namespace std;
//function prototypes
int readalldata(longint[],char[],string[],string[],int[],double[],const int);void computeotp(int[],int[],double[],double[],int);voidcomputegp(double[],int[],double[],double[],double[],int);void computetaxrate(double[],double[],int);void computemtaxrate(char[],double[],double[],int);voidcomputenetpay(double[],double[],double[],double[],double[],int);double computesum(double[],int);double computeavg(double,int);void sortnetpay(double[],int);void displayarrays(longint[],char[],string[],string[],int[],double[],int[],double[],double[],double[],double[],double[],float,double,double[],int);
int main(){const int MAXSIZE = 100; int n;long int employeeid[MAXSIZE];char marital[MAXSIZE];string firstname[MAXSIZE], lastname[MAXSIZE];double hourlyrate[MAXSIZE], grosspay[MAXSIZE], netpay[MAXSIZE],taxrate[MAXSIZE], mtaxrate[MAXSIZE], taxamount[MAXSIZE],regpay[MAXSIZE], otpay[MAXSIZE];double sum;double avg;
int hoursworked[MAXSIZE], othours[MAXSIZE];
//FUCNTION CALLS
n =readalldata(employeeid,marital,firstname,lastname,hoursworked,hourlyrate,MAXSIZE); computeotp(hoursworked,othours,hourlyrate,otpay,n);computegp(grosspay,hoursworked,hourlyrate,otpay,regpay,n);computetaxrate(grosspay,taxrate,n);computemtaxrate(marital,mtaxrate,taxrate,n);computenetpay(taxamount,grosspay,taxrate,mtaxrate,netpay,n);sum=computesum(netpay,n);avg=computeavg(sum,n);sortnetpay(netpay,n);displayarrays(employeeid,marital,firstname,lastname,hoursworked,hourlyrate,othours,otpay,regpay,grosspay,taxamount,netpay,sum,avg,netpay,n);return 0;}//end of main function
//FUCNTION DEFINITIONSint readalldata(long int employeeid[],char marital[],stringfirstname[],string lastname[],int hoursworked[],doublehourlyrate[],int n){ifstream fin("payroll3.txt");n = 0;while(fin>>employeeid[n]>>marital[n]>>firstname[n]>>lastname[n]>>hoursworked[n]>>hourlyrate[n]){n++;}//while
fin.close();return n;}//readall
void computeotp(int hoursworked[],int othours[],doublehourlyrate[],double otpay[],int n){ for(int i = 0;i < n;i++){ if (hoursworked >= 40) othours =hoursworked - 40; otpay = othours * hourlyrate * 1.5;
if (hoursworked < 40) otpay =0; else othours = 0;}//if}//OTPAY
void computegp(double grosspay[],int hoursworked[],doublehourlyrate[],double otpay[],double regpay[],int n){ for(int i = 0;i < n;i++){ grosspay =(hoursworked[i] * hourlyrate[i]) +otpay[i]; regpay[i] = (grosspay[i] -otpay[i]); }//for}//GROSSPAY
void computetaxrate(double grosspay[],double taxrate[],intn){ for(int i = 0;i < n;i++){ if(grosspay[i] > 4000) taxrate[i] =0.40; else if(grosspay[i] > 3000) taxrate[i] =0.30; else if(grosspay[i] > 1000) taxrate[i] =0.20; else taxrate[i] = 0.10;}//for}//TAXRATE
void computemtaxrate(char marital[],double mtaxrate[],doubletaxrate[],int n){ for(int i = 0;i < n;i++){ if(marital[i] == 'S' || marital[i] == 's')mtaxrate[i] += 0.05; else if(marital[i] == 'H' || marital[i] == 'h')mtaxrate[i] -= 0.05; else taxrate[i];}//for}//MTAXRATE
void computenetpay(double taxamount[],double grosspay[],doubletaxrate[],double mtaxrate[],double netpay[],int n){ for(int i = 0;i < n;i++){ taxamount[i] = (grosspay[i] * (taxrate[i] +mtaxrate[i])); netpay[i] = grosspay[i] - taxamount[i];}//for}//NETPAYdouble computesum(double netpay[], int n){ double sum=0; for(int i = 0;i < n; i++){ sum=sum+netpay[i];
}//for return sum;}//SUM
double computeavg(double sum, int n){ double avg; for(int i=0; i<n; i++){ avg=sum/n; }//for return avg;}//AVG
void sortnetpay(double netpay[],int n){for(int i=0;i<n-1;i++) for(int j=0;j<n-i-1;j++) if(netpay[j]>netpay[j+1]){ float temp=netpay[j]; netpay[j]=netpay[j+1]; netpay[j+1]=temp;}}
void displayarrays(long int employeeid[],char marital[],stringfirstname[],string lastname[],int hoursworked[],doublehourlyrate[],int othours[],double otpay[],double regpay[],double grosspay[],double taxamount[],double netpay[],floatsum,double avg, int n){
cout<<" DR. EBRAHIMI'S PAYROLL INSTITUTE"<<endl;cout<<endl;cout<<endl;cout<<setw(15),setprecision(1),setiosflags(ios::fixed|ios::showpoint|ios::left);cout<<"EMP ID"<<setw(14)<<"MARTIALSTAT"<<setw(12)<<"FIRSTNAME"<<setw(12)<<"LAST NAME"<<setw(6)<<"HW"<<setw(6)<<"HR"<<setw(6)<<"OTP"<<setw(6)<<"REGP"<<setw(7)<<"GROSS"<<setw(10)<<"TAX"<<setw(10)<<"NET"<<endl;cout<<endl;for(int i = 0;i < n;i++){cout<<setw(15),setprecision(1),setiosflags(ios::fixed|ios::showpoint|ios::left);cout<<employeeid[i]<<setw(14)<<marital[i]<<setw(12)<<firstname[i]<<setw(12)<<lastname[i]<<setw(6)<<hoursworked[i]<<setw(6)<<hourlyrate[i]<<setw(6)<<otpay[i]<<setw(6)<<regpay[i]<<setw(7)<<grosspay[i]<<setw(10)<<taxamount[i]<<setw(10)<<netpay[i]<<endl;}//for
cout<<endl;cout<<"SUM OF EMPLOYEE NETPAY IS:$"<<sum<<endl;cout<<"AVERAGE OF NETPAY OF EMPLOYEES IS:$"<<avg<<endl;for(int i = 0;i < n;i++){cout<<"NETPAY BEFORE SORTING :"<<netpay[i]<<endl;cout<<"NETPAY AFTER SORTING :"<<netpay[i]<<endl;}
}//display