IRM - Chapter - 6e - 02(6)

2019-04-23 19:55

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

This problem involves payroll and uses the selection construct. A possible restatement: An hourly employee's regular payRate is $16.78/hour for hoursWorked <= 40 hours. If hoursWorked > 40 hours, then (hoursWorked -40) is paid at an overtime premium rate of 1.5 * payRate. FICA (social security) tax is 6% and Federal income tax is 14%. Union dues of $10/week are withheld. If there are 3 or more covered dependents, $15 more is withheld for dependent health insurance.

a) Write a program that, on a weekly basis, accepts hours worked then outputs gross pay,

26

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

each withholding amount, and net (take-home) pay.

b) Add 'repeat at user discretion' feature.

I was unpleasantly surprised to find that with early GNU g++ , you cannot use a leading 0 (such as an SSN 034 56 7891) in a sequence of integer inputs. The gnu iostreams library took the integer to be zero and went directly to the next input! You either have to either use an array of char, or 9 char variables to avoid this restriction.

Otherwise, the code is fairly straight forward.

//file Ch2Prob7.cc

27

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

//pay roll problem:

//Inputs: hoursWorked, number of dependents

//Outputs: gross pay, each deduction, net pay //

//This is the 'repeat at user discretion' version //Outline:

//In a real payroll program, each of these values would be //stored in a file after the payroll calculation was printed //to a report. //

//regular payRate = $10.78/hour for hoursWorked <= 40 //hours. //If hoursWorked > 40 hours,

28

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

// overtimePay = (hoursWorked - 40) * 1.5 * PAY_RATE.

//FICA (social security) tax rate is 6%

//Federal income tax rate is 14%. //Union dues = $10/week . //If number of dependents >= 3 // $15 more is withheld for dependent health insurance. //

#include using namespace std;

const double PAY_RATE = 16.78; const double SS_TAX_RATE = 0.06; const double FedIRS_RATE = 0.14; const double STATE_TAX_RATE = 0.05;

29

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Savitch

Problem Solving w/ C++, 6e Instructor’s Resource Guide

Chapter 2

const double UNION_DUES = 10.0; const double OVERTIME_FACTOR = 1.5; const double HEALTH_INSURANCE = 15.0;

int main() {

double hoursWorked, grossPay, overTime, fica,

incomeTax, stateTax, union_dues, netPay; int numberDependents, employeeNumber; char ans;

//set the output to two places, and force .00 for cents

30

Copyright ? 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley


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

下一篇:李春城案

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

马上注册会员

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