You are on page 1of 9

Solution Manual for An Introduction to Programming

with C++, 8th Edition

To download the complete and accurate content document, go to:


https://testbankbell.com/download/solution-manual-for-an-introduction-to-programmin
g-with-c-8th-edition/
Solution Manual for An Introduction to Programming with C++, 8th Edition

An Introduction to Programming with C++: Eighth Edition


Chapter 8 Answers

Review Questions
1. a after
2. a do while
3. d both b and c
4. a 0, 1, 2, 3, 4
5. b 16, 12
6. b 8
7. d 3, 5
8. a ***
***
9. d 30

Exercises – Pencil and Paper


1. The answer to this TRY THIS Exercise is located at the end of Chapter 8 in the book.
2. The answer to this TRY THIS Exercise is located at the end of Chapter 8 in the book.
3. for (int outer = 1; outer <= 2; outer +=1)
{
for (int nested = 3; nested > 0; nested -= 1)
cout << nested << " ";
//end for
cout << endl;
} //end for
4. repeat while (there are customers in line)
repeat while (the customer has a book that needs signing)
accept the book from the customer
place the book on the table
open the front cover of the book
sign your name on the first page
close the book
return the book to the customer
end repeat
thank the customer
end repeat
5. } while (inStock > reorder);
6. do //begin loop
{
cout << evenNum << endl;
evenNum += 2;
} while (evenNum < 11);
7. for (int num = 15; num >= 0; num -= 3)
cout << num << endl;
//end for
8. To debug the code, change the outer loop’s condition argument to either row <= 4 or row < 5. Also
change the nested loop’s condition argument to col <= row.

Exercises – Computer
9. The answer to this TRY THIS Exercise is located at the end of Chapter 8 in the book. The code is entered
in the TryThis9.cpp file, which is contained in either the Cpp8\Chap08\TryThis9 Project-IM folder
(Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).

Visit TestBankBell.com to get complete for all chapters


10. The answer to this TRY THIS Exercise is located at the end of Chapter 8 in the book. The code is entered
in the TryThis10.cpp file, which is contained in either the Cpp8\Chap08\TryThis10 Project-IM folder
(Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
11. See the ModifyThis11.cpp file, which is contained in either the Cpp8\Chap08\ModifyThis11 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
12. See the ModifyThis12.cpp file, which is contained in either the Cpp8\Chap08\ModifyThis12 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
13. See the Introductory13.cpp file, which is contained in either the Cpp8\Chap08\Introductory13 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
14. See the Introductory14.cpp file, which is contained in either the Cpp8\Chap08\Introductory14 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
15. See the Intermediate15.cpp file, which is contained in either the Cpp8\Chap08\Intermediate15 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
16. See the Intermediate16.cpp file, which is contained in either the Cpp8\Chap08\Intermediate16 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
17. See the Intermediate17.cpp file, which is contained in either the Cpp8\Chap08\Intermediate17 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
18. See the Intermediate18.cpp file, which is contained in either the Cpp8\Chap08\Intermediate18 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft). The sentinel value may vary.

Input Processing Output


beginning salary Processing items: raise (for 3 years at
raise rate (counter: 3% to 6% new salary different raise rates)
in increments of 1%)
year (counter: 1 to 3)

Algorithm:
1. enter the beginning salary
2. repeat while (the beginning salary > 0)
assign the beginning salary to the new salary

repeat for (raise rate from 3%


to 6% in increments of 1%)
display the current raise rate

repeat for (year from 1 to 3)


display the current year

calculate the raise by multiplying


the new salary by the raise rate

display the raise

add the raise to the new salary


end repeat
display a blank line
assign the beginning salary to the new salary
end repeat
enter the salary
end repeat
beginning salary new salary raise rate year raise
30000 30000 .03 1 900
30900 2 927
31827 3 954.81
32781.81 4
30000 .04 1 1200
31200 2 1248
32448 3 1297.92
33745.92 4
30000 .05 1 1500
31500 2 1575
33075 3 1653.75
34728.75 4
30000 .06 1 1800
31800 2 1908
33708 3 2022.48
35730.48 .07 4
50000 50000 .03 1 1500
51500 2 1545
53045 3 1591.35
54636.35 4
50000 .04 1 2000
52000 2 2080
54080 3 2163.20
56243.20 4
50000 .05 1 2500
52500 2 2625
55125 3 2756.25
57881.25 4
50000 .06 1 3000
53000 2 3180
56180 3 3370.80
59550.80 .07 4
–1
IPO chart information C++ instructions
Input
beginning salary int beginSalary = 0;
raise rate (counter: 3% to 6%in this variable is created and initialized in the for clause
increments of 1%)
year (counter: 1 to 3) this variable is created and initialized in the for clause

Processing
new salary
double newSalary = 0.0;
Output
double raise = 0.0;
raise (for 3 years at different raise rates)

Algorithm cout << "Salary (negative number or 0


1. enter the beginning salary to end): ";
cin >> beginSalary;
2. repeat while (the beginning salary > 0) while (beginSalary > 0)
{
assign the beginning salary to the newSalary = beginSalary;
new salary

repeat for (raise rate from 3% for (double rate = .03; rate < .07;
rate += .01)
to 6% in increments of 1%)
{
cout << "Raise rate: "
display the current raise rate << rate * 100 << "%" << endl;

repeat for (year from 1 to 3) for (int year = 1; year < 4; year +=
1)
{
display the current year cout << "Year " << year << ":";

calculate the raise by multiplying raise = newSalary * rate;


the new salary by the raise rate
cout << " Raise: $" << raise << endl;
display the raise

add the raise to the new salary newSalary += raise;


end repeat } //end for
display a blank line cout << endl;

assign the beginning salary to newSalary = beginSalary;


the new salary
} //end for
end repeat
cout << endl << "Salary (negative
enter the salary number or 0 to end): ";
cin >> beginSalary;
end repeat } //end while
beginSalary newSalary rate year raise
0 0.0 0.0
30000 30000 .03 1 900
30900 2 927
31827 3 954.81
32781.81 4
30000 .04 1 1200
31200 2 1248
32448 3 1297.92
33745.92 4
30000 .05 1 1500
31500 2 1575
33075 3 1653.75
34728.75 4
30000 .06 1 1800
31800 2 1908
33708 3 2022.48
35730.48 .07 4
50000 50000 .03 1 1500
51500 2 1545
53045 3 1591.35
54636.35 4
50000 .04 1 2000
52000 2 2080
54080 3 2163.20
56243.20 4
50000 .05 1 2500
52500 2 2625
55125 3 2756.25
57881.25 4
50000 .06 1 3000
53000 2 3180
56180 3 3370.80
59550.80 .07 4
–1
19. See the Intermediate19.cpp file, which is contained in either the Cpp8\Chap08\Intermediate19 Project-IM
folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft). The sentinel values may vary.

Input Processing Output


sales Processing items: total sales
dealership (counter: 1 to 3)

Algorithm:
1. repeat for (dealership from 1 to 3)
enter the sales

repeat while (the sales are greater than 0)


add the sales to the total sales
enter the sales
end repeat
end repeat
2. display total sales

dealership sales total sales


1 23000 23000
15000 38000
0
2 12000 50000
16000 66000
34000 100000
10000 110000
0
3 64000 174000
12000 186000
70000 256000
0
4
IPO chart information C++ instructions
Input
sales int dealerSales = 0;

Processing
dealership (counter: 1 to 3)
this variable is created and initialized in the for clause
Output
total sales int totalSales = 0;

Algorithm for (int dealer = 1; dealer < 4;


1. repeat for (dealership from 1 to 3)
dealer += 1)
{
cout << "First sales amount for
enter the sales dealership " << dealer << " (0
or a negative number to end): ";
cin >> dealerSales;

repeat while (the sales are greater than 0) while (dealerSales > 0)
{
add the sales to the total sales totalSales += dealerSales;
cout << "Next sales amount
enter the sales
for dealership " << dealer
<< " (0 or a negative
number to end): ";
cin >> dealerSales;
end repeat }//end while
cout << endl;
end repeat }//end for
2. display total sales cout << "Total sales: $" << totalSales
<< endl;

dealer dealerSales totalSales


0 0
1 23000 23000
15000 38000
0
2 12000 50000
16000 66000
34000 100000
10000 110000
0
3 64000 174000
12000 186000
70000 256000
0
4

20. See the Advanced20.cpp file, which is contained in either the Cpp8\Chap08\Advanced20 Project-IM folder
(Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
21. See the Advanced21.cpp file, which is contained in either the Cpp8\Chap08\Advanced21 Project-IM folder
(Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
Solution Manual for An Introduction to Programming with C++, 8th Edition

22. See the SwatTheBugs22.cpp file, which is contained in either the Cpp8\Chap08\SwatTheBugs22 Project-
IM folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft). To debug the program, change the outer
loop’s update argument to outer += 1. Also enclose the number += 2; and cout << number
<< " "; statements in a set of braces.

Visit TestBankBell.com to get complete for all chapters

You might also like