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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;
//function prototype
void GetData(string FullNamef[], int EmployeeNumberf[], float HoursWorkedf[],
float HourlyRatef[], int &Indexf);
void ComputePay(float HoursWorkedf[], float HourlyRatef[], float TotalPayf[],
float &TotalPayrollf, int Indexf);
void PrintResults(string FullNamef[],int EmployeeNumberf[],float HoursWorkedf[],
float HourlyRatef[],float TotalPayf[],
float &TotalPayrollf, int Indexf);
int menu();
//main body
//global constants
const int MAXSIZE = 20;
int main()
{
//local identifiers
string FullName[MAXSIZE];
int EmployeeNumber[MAXSIZE];
float HoursWorked[MAXSIZE];
float HourlyRate[MAXSIZE];
float TotalPay[MAXSIZE];
float TotalPayroll = 0.0;
int Index = 0;
int DesignCode;
char Another='y';
int choice;
int n;
//input module
do
{
DesignCode=menu();
switch(DesignCode)
{
case 1://GET DATA
GetData(FullName, EmployeeNumber, HoursWorked, HourlyRate, Index);
break;
case 2://GROSS PAY
ComputePay(HoursWorked, HourlyRate, TotalPay, TotalPayroll,Index);
break;
case 3://PRINT REPORT
PrintResults(FullName, EmployeeNumber, HoursWorked,
HourlyRate, TotalPay, TotalPayroll, Index);
break;
case 4://EXIT
cout<<"Thank you very much...GOODBYE....!!!"<<endl;
break;
default:
cout<<"Invalid menu choice selected - Try again" << endl;
system("PAUSE");
system("CLS");
}//end of switch
cout<<endl;
}while(DesignCode != 4);
return 1;
}//end of program
//function defination
int menu()
{
int choice;
cout<<setw(45)<<"Patty's Payroll Program\n";
cout<<endl;
cout<<setw(49)<<"Please choose from the following:\n";
cout<<"\t\t\n";
cout<<setw(21)<<" 1. "<<"Input Employee Data\n";
cout<<setw(21)<<" 2. "<<"Compute Gross Pay\n";
cout<<setw(21)<<" 3. "<<"Print Report\n";
cout<<setw(21)<<" 4. "<<"Exit\n";
cin>>choice;
return choice;
}
void GetData(string FullNamef[], int EmployeeNumberf[], float HoursWorkedf[],
float HourlyRatef[], int &Indexf)
{
string FirstName, LastName, FullName;
char Another;
do
{
cout<<"Please enter your first and last name separated by a space?\n";
cin >> FirstName >> LastName;
FullName = FirstName + " " + LastName;
FullNamef[Indexf] = FullName;
cout<<"Please enter your four digit Employee Number?\n";
cin>>EmployeeNumberf[Indexf];
cout<<"How many hours did you work last week?\n";
cin>>HoursWorkedf[Indexf];
cout<<"What is your hourly rate?\n";
cin>>HourlyRatef[Indexf];
cout<<"Do you have another employee to process<Y or N>?\t";
cin>>Another;
if((Another=='Y')||(Another=='y'))
{
Indexf++;
system("PAUSE");
system("CLS");
}//end of if
}while((Another=='Y')||(Another=='y'));
//end of while
return;
}
void ComputePay(float HoursWorkedf[], float HourlyRatef[], float TotalPayf[],
float &TotalPayrollf, int Indexf)
{
//Local Identifiers
TotalPayrollf = 0;
float RegularPay, OverTimePay, DoubleTimePay;
//computations
for(int i=0; i<=Indexf; i++)
{
if (HoursWorkedf[i] <=40)
TotalPayf[i]=HourlyRatef[i]*HoursWorkedf[i];
else
if (HoursWorkedf[i] <=60)
{
RegularPay = HourlyRatef[i]*40;
OverTimePay = (HoursWorkedf[i]-40)*HourlyRatef[i]*1.5;
TotalPayf[i] = RegularPay + OverTimePay;
}
else
{
RegularPay = HourlyRatef[i]*40;
OverTimePay = HourlyRatef[i]*1.5*20;
DoubleTimePay =(HoursWorkedf[i]-60)*HourlyRatef[i]*2;
TotalPayf[i]= RegularPay + OverTimePay + DoubleTimePay;
}
TotalPayrollf += TotalPayf[i];
}
return;
}
void PrintResults(string FullNamef[],int EmployeeNumberf[],float HoursWorkedf[],
float HourlyRatef[],float TotalPayf[],
float &TotalPayrollf, int Indexf)
{
//local identifiers
float RegularPay = 0.0, OverTimePay = 0.0, DoubleTimePay = 0.0;
cout<<setw(45)<<" PAYROLL REPORT "<<endl;
cout<<setw(45)<<"----------------"<<endl;
cout<<setw(3)<<"No."<<setw(12)<<" Name "<<setw(8)<<" ID # "<<setw(6)
<<"HWrked"<<setw(8)<<"HrRate"<<setw(8)<<"RegPay"<<setw(8)
<<"OvtPay"<<setw(8)<<"DblPay"<<setw(8)<<"TotPay"<<setw(10)
<<"Payroll"<<endl;
cout<<setw(3)<<"---"<<setw(12)<<" ---- "<<setw(8)<<" ---- "<<setw(6)
<<"------"<<setw(8)<<"------"<<setw(8)<<"------"<<setw(8)
<<"------"<<setw(8)<<"------"<<setw(8)<<"------"<<setw(10)
<<"-------";
for(int i=0; i<Indexf; i++)
{
cout<<setw(3)<<(i+1)<<setw(12)<<FullNamef[i]<<setw(8)<<EmployeeNumberf[i]<<setw(6)
<<HoursWorkedf[i]<<setw(5)<<HourlyRatef[i]<<setw(7)<<RegularPay<<setw(7)
<<OverTimePay<<setw(7)<<DoubleTimePay<<setw(8)<<TotalPayf[i]<<setw(10)
<<TotalPayrollf<<endl<<endl<<endl;
}
return;
}//end of function
|