Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
cout.setf(ios::showpoint); cout.setf(ios::fixed); cout.precision(2); // compute payroll do {
cout << \(digits only,”
<< “ no spaces or dashes) \\n”;
cin >> employeeNumber ; cout << “Please the enter hours worked and number “
<< “of employees.” << endl;
cin >> hoursWorked ; cin >> numberDependents;
31
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
cout << endl;
if (hoursWorked <= 40 ) grossPay = hoursWorked * PAY_RATE;
else {
overTime =
(hoursWorked - 40) * PAY_RATE * OVERTIME_FACTOR;
grossPay = 40 * PAY_RATE + overTime;
}
fica = grossPay * SS_TAX_RATE;
32
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
incomeTax = grossPay * FedIRS_RATE;
stateTax = grossPay * STATE_TAX_RATE;
netPay =
grossPay - fica - incomeTax
- UNION_DUES - stateTax;
if ( numberDependents >= 3 ) netPay = netPay - HEALTH_INSURANCE;
//now print report for this employee:
cout << \
33
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
<< employeeNumber << endl;
cout << \hoursWorked << endl;
cout << \<< PAY_RATE << endl;
if (hoursWorked > 40 ) {
cout << \worked: \
<< hoursWorked - 40 << endl;
cout << \premium: \
<< OVERTIME_FACTOR << endl;
34
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
}
cout << \grossPay << endl;
cout << \<< fica << endl;
cout << \withheld: \
<< incomeTax << endl; cout << \\
if (numberDependents >= 3 ) cout << \Premium withheld: \
<< HEALTH_INSURANCE << endl;
35
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley