An Introduction to Programming with C++: Eighth Edition
Chapter 1 Answers
Review Questions
1. d sorting
2. c sequence
3. d sequence
Exercises
1. The answer to this TRY THIS Exercise is located at the end of Chapter 1 in the book.
2. The answer to this TRY THIS Exercise is located at the end of Chapter 1 in the book.
3. repeat for (each customer buying a TV)
enter the original price of the TV
4.
1. repeat (4 times)
enter a number
5.
repeat for (each component name on the list)
read the component name from the list
6. Version 1:
repeat for (each customer)
enter the number of tickets
Version 2:
repeat for (each customer)
enter the number of tickets
if (the number of tickets is less than or equal to 4)
7.
1. repeat (6 times)
if (the flower is red)
pick the flower with your right hand
8.
repeat (5 times)
enter the employee’s name, hours worked, and pay rate
if (hours worked is less than or equal to 40)
calculate gross pay = hours worked times pay rate
else
9. repeat (for each employee)
enter the employee’s payment schedule and annual salary
if (the employee’s payment schedule is weekly)
10.
1. multiply 7 by 5, giving a product of 35
2. divide 20 by 2, giving a quotient of 10
11.
1. enter Store A’s price and Store B’s price
2. calculate the cost at Store A by dividing Store A’s price by 2 and then
adding the result to Store A’s price
12.
1. repeat (3 times)
walk forward one complete step
end repeat
2. turn left 90 degrees
3. repeat (2 times)
walk forward one complete step
end repeat
10. repeat (2 times)
turn right 90 degrees
end repeat
11. sit down
13.
1. walk into the maze
2. turn left 90 degrees
3. repeat until (you are directly in front of a wall)
walk forward one complete step
end repeat
end repeat
8. turn left 90 degrees
9. repeat until (you are directly in front of a wall)
walk forward one complete step
end repeat
10. turn left 90 degrees
11. repeat until (you are directly in front of a wall)
walk forward one complete step