An Introduction to Programming with C++: Eighth Edition
Chapter 2 Answers
Review Questions
1. b Analyze the problem
2. b output
3. a input
Exercises
1. The answer to this TRY THIS Exercise is located at the end of Chapter 2 in the book.
Input Processing Output
miles driven Processing items: none miles per gallon
gallons used cost per mile driven
cost per gallon
Algorithm:
1. enter the miles driven, gallons used, and
cost per gallon
miles driven gallons used cost per gallon miles per gallon cost per mile driven
324 17 3.10 19.06 .16
4.
Input Processing Output
salary Processing items: none weekly gross pay
Algorithm:
1. enter the salary
salary weekly gross pay biweekly gross pay
56700 1090.38 2180.77
32660 628.08 1256.15
5.
Input Processing Output
sandwiches Processing items: pounds of beef
ounces per sandwich ounces of beef
Algorithm:
1. enter the sandwiches and meat per sandwich
sandwiches ounces per sandwich ounces of beef pounds of beef
50 4 200 12.5
224 2 448 28
6. The data shown in the second desk-check will vary.
Input Processing Output
first-class tickets Processing items: total paid
coach price
Algorithm:
1. enter the first-class tickets, coach tickets,
first-class price, and coach price
2. calculate the first-class total by multiplying
first-class tickets coach tickets first-class price coach price
9 52 125 90
12 40 100 50
7. The data shown in the desk-check table will vary.
Input Processing Output
assessed value Processing items: none property tax
Algorithm:
1. enter the assessed value
assessed value property tax
150000 2625
225000 3937.5
8. The data shown in the second desk-check will vary.
Input Processing Output
dental charge Processing items: none total insurance pays
total Tania pays
Algorithm:
1. enter the dental charge
2. calculate the total insurance pays by subtracting
dental charge total insurance pays total Tania pays
110 76.5 33.5
65 38.25 26.75
9. The data shown in the second desk-check will vary.
Input Processing Output
length in feet Processing items: cost of carpeting
width in feet area in square feet
cost per sq. ft.
Algorithm:
1. enter the length in feet, width in feet, and cost per sq. ft.
2. calculate the area in square feet by multiplying the
length in feet width in feet cost per sq. ft. area in square feet cost of carpeting
25 30 5.65 750 4237.5
10 12 2.25 120 270
10. The data shown in the second desk-check will vary.
Input Processing Output
gross pay per paycheck Processing items: total contribution
Carlos rate total rate
employer rate
Algorithm:
1. enter the gross pay per paycheck, Carlos rate,
and employer rate
2. calculate the total rate by adding the Carlos rate
to the employer rate
gross pay per paycheck Carlos rate employer rate total rate total contribution
1465 .04 .02 .06 2109.6
11. The data shown in the desk-check table will vary.
Input Processing Output
base fee Processing items: none total cost
number of guests
fee per guest
Algorithm:
1. enter the base fee, number of guests, and fee per guest
2. calculate the total cost by multiplying the number of
base fee number of guests fee per guest total cost
100 50 5 350
12.
Input Processing Output
distance in feet Processing items: travel seconds
speed in mph speed in feet per hour
speed in feet per second
Algorithm:
1. enter the distance in feet and speed in mph
2. calculate the speed in feet per hour by multiplying
the speed in mph by 5280 (There are 5280 feet in a mile.)
distance in feet speed in mph speed in feet per hour speed in feet per second
60.5 105 554400 154
54 89 469920 130.5333
13. The data shown in the second desk-check will vary.
Input Processing Output
hours worked Processing items: none gross pay
hourly pay rate FWT
Algorithm:
1. enter the hours worked, hourly pay rate, FWT rate,
FICA rate, and state tax rate
2. calculate the gross pay by multiplying the
hours worked by the hourly pay rate
3. calculate the FWT by multiplying the gross
pay by the FWT rate
hours worked hourly pay rate FWT rate FICA rate state tax rate
30 10 .2 .08 .04
gross pay FWT FICA state tax net pay
14. The modifications are shaded in the algorithm.
Input Processing Output
number purchased Processing items: total due
Algorithm:
1. enter the number purchased, folder price, and sales tax rate
2. calculate the subtotal by multiplying the number
purchased by the folder price