An Introduction to Programming with C++: Eighth Edition
Chapter 3 Answers
Review Questions
1. d syntax
2. a int quantity = 0;
3. d semicolon
4. d all of the above
Exercises
1. The answer to this TRY THIS Exercise is located at the end of Chapter 3 in the book.
IPO chart information C++ instructions
Input
latex price (2.25) const double LATEX_PRICE = 2.25;
Mylar price (3.75) const double MYLAR_PRICE = 3.75;
Processing
total latex cost double totalLatexCost = 0.0;
Output
total cost double totalCost = 0.0;
4. The values in the desk-check table are rounded to two decimal places. The data used in the second
desk-check will vary.
Input Processing Output
banana price Processing items: total cost
apple price banana cost
Algorithm:
1. enter the banana price, apple price, banana pounds,
and apple pounds
2. calculate the banana cost by multiplying the banana
pounds by the banana price
3. calculate the apple cost by multiplying the apple pounds
banana price apple price banana pounds apple pounds sales tax rate
0.99 1.89 2 3.5 0.03
1.25 1.69 3 5 0.03
banana cost apple cost subtotal sales tax total cost
IPO chart information C++ instructions
Input
banana price double bananaPrice = 0.0;
apple price double applePrice = 0.0;
Processing
banana cost double bananaCost = 0.0;
apple cost double appleCost = 0.0;
Output
total cost double totalCost = 0.0;
5. The data used in the second desk-check will vary.
Input Processing Output
field goals Processing items: total points
touchdowns field goal points
Algorithm:
1. enter the field goals, touchdowns, one-point conversions,
two-point conversions, and safeties
2. calculate field goal points by multiplying field goals by 3
3. calculate touchdown points by multiplying
touchdowns by 6
field goals touchdowns one-point conversions two-point conversions safeties
3 2 2 0 1
2 4 2 1 0
field goal points touchdown points points for conversions points for safeties
9 12 2 2
IPO chart information C++ instructions
Input
field goals int fieldGoals = 0;
touchdowns int touchdowns = 0;
safeties int safeties = 0;
Processing
field goal points int fieldGoalPts = 0;
Output
total points int totalPts = 0;
6.
Input Processing Output
diameter Processing items: total price
price per foot circumference
pi (3.1416)
Algorithm:
1. enter the diameter and price per foot
diameter price per foot pi circumference total price
35 2 3.1416 109.956 219.912
15.5 3.5 3.1416 48.6948 170.4318
IPO chart information C++ instructions
Input
diameter double diameter = 0.0;
Processing
circumference double circumference = 0.0;
7. The data used in the second desk-check will vary.
Input Processing Output
team 2-pt baskets Processing items: Michael contribution
team 3-pt baskets team score
Algorithm:
1. enter the team 2-pt baskets, team 3-pt baskets, team
free throw pts, Michael 2-pt baskets, Michael 3-pt
baskets, Michael free throw points
2. calculate the team score by first multiplying the team
3. calculate the Michael score by first multiplying the
Michael 2-pt baskets by 2, then multiplying the Michael
3-pt baskets by 3, and then adding both results to the
Michael free throw pts
4. calculate the Michael contribution by dividing the
team 2-pt baskets team 3-pt baskets team free throw pts Michael 2-pt baskets
25 14 10 11
20 6 15 4
Michael 3-pt baskets Michael free throw pts team score Michael score
Michael contribution
36.3
IPO chart information C++ instructions
Input
team 2-pt baskets int team2Pt = 0;
team 3-pt baskets int team3Pt = 0;
Processing
team score int teamScore = 0;
Output
Michael contribution double michaelContrib = 0;
8. The desk-check data will vary.
Input Processing Output
gross pay Processing items: total deposited
gross pay percentage gross pay savings
gross pay gross pay percentage bonus savings number of paychecks
1000 .1 150 52
500 .05 150 52
IPO chart information C++ instructions
Input
gross pay double grossPay = 0.0;
Processing
gross pay savings double grossSavings = 0.0;
9. The desk-check data will vary.
Input Processing Output
strawberry sales Processing items: none projected strawberry sales
blueberry sales projected blueberry sales
Algorithm:
1. enter strawberry sales, blueberry sales, raspberry
sales, and projected increase
2. calculate projected strawberry sales by multiplying
strawberry sales by the projected increase, and then adding
the result to the strawberry sales
strawberry sales blueberry sales raspberry sales projected increase
10000 12000 2000 0.1
2500.55 600.75 1050.67 0.25
projected strawberry sales projected blueberry sales projected raspberry sales
IPO chart information C++ instructions
Input
strawberry sales double strawSales = 0.0;
Processing
none
Output
projected strawberry sales double projStrawSales = 0.0;
10. The data used in the second desk-check will vary.
Input Processing Output
initial odometer Processing items: miles per gallon
Algorithm:
1. enter the initial odometer, final odometer, gallons at
first fill, and gallons at second fill
2. calculate the total miles by subtracting the initial
initial odometer final odometer gallons at first fill gallons at second fill
5500 6280 15.5 18.7
22010 22900 18 15
total miles total gallons miles per gallon
IPO chart information C++ instructions
Input
initial odometer double initialOdometer = 0.0;
Processing
total miles double totalMiles = 0.0;
total gallons double totalGals = 0.0;
Output
miles per gallon double mpg = 0.0;
11. The modifications are shaded.
IPO chart information C++ instructions
Input
original price double original = 0.0;