IRM - Chapter - 6e - 02(5)

2019-04-23 19:55

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


IRM - Chapter - 6e - 02(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:李春城案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: