Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
retroactive = (salary – oldSalary)/2;
cout << \salary << endl;
cout << \<< monthly << endl;
cout << \due: \
<< retroactive << endl; return 0; }
17:50:12:~/AW$ a.out
Enter current annual salary. 100000
I'll return new annual salary, monthly salary, and retroactive pay.
new annual salary 107600
21
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
new monthly salary 8966.67 retroactive salary due: 3800
4. Retroactive Salary
// File: Ch2.4.cpp
// Modify program from Problem #3 so that it calculates retroactive // salary for a worker for a number of months entered by the user.
//Given a 7.6% pay increase, //input salary
//input number of months to compute retroactive salary
//Output new annual and monthly salaries, retroactive pay
#include
const double INCREASE = 0.076;
22
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
int main() {
using std::cout; using std::cin; using std::endl;
double oldSalary, salary,
monthly, oldMonthly, retroactive; int numberOfMonths; // number of months to pay retroactive increase char ans;
cout << \salary and a number of months\\n\ << \compute retroactive pay.\\n\
<< \salary, monthly \
<< \pay.\
cin >> oldSalary;//old annual salary
cin >> numberOfMonths;
23
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
salary = oldSalary *
(1+INCREASE); //new annual salary oldMonthly = oldSalary/12; monthly = salary/12;
retroactive = (monthly -
oldMonthly) * numberOfMonths; // retroactive = (salary - oldSalary)/2; // six months retroactive pay increase.
cout << \salary << endl;
cout << \<< monthly << endl;
cout << \\
<< retroactive << endl;
return 0; } /*
Typical run
24
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Savitch
Problem Solving w/ C++, 6e Instructor’s Resource Guide
Chapter 2
Enter current annual salary and a number of months
for which you wish to compute retroactive pay.
I'll return new annual salary, monthly salary, and retroactive pay. 12000 9
new annual salary 12912 new monthly salary 1076
retroactive salary due: 684 Press any key to continue
*/
5. No solution provided.
6. No solution provided.
7. Payroll
25
Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley