Page | 1
v v
,https://www.stuvia.com/user/Smartscroll
CHAPTER 1, INTRODUCTION v v
TABLE OF CONTENTS
v v v
Exercise Solutions v 1
Exercise 1.1 v 1
Exercise 1.2 v 2
Exercise 1.3 v 3
Review Questions Answers v v 4
Programming Exercises Solutions v v 8
Debugging Exercises Solutions 8 v v v
EXERCISESOLUTIONS v
EXERCISE 1.1
v v
1. List three common types of computing agents.
v v v v v v
Solution:
Human beings, desktop computers, cell phones
v v v v v
2. Write an algorithm that describes the second part of the process of making change (counting out the coins
v v v v v v v v v v v v v v v v v
and bills).
v v
Solution:
There are various ways to do this, but here is one:
v v v v v v v v v v
Repeat
Select the largest unit of money that is less than or equal to the remaining change Subtract this unit from the
v v v v v v v v v v v v v v v v v v v v
remaining change
v v
Until the remaining change is 0
v v v v v
The collection of units selected represent the change
v v v v v v v
Page | 2v v
,https://www.stuvia.com/user/Smartscroll
3. Write an algorithm that describes a common task, such as baking a cake.
v v v v v v v v v v v v
Solution:
There are various ways to do this, but here is one:
v v v v v v v v v v
Preheat an oven to 375 degrees v v v v v
Add 1 cup of water and 1 egg to a mixing bowl
v v v v v v v v v v v
Beat the liquid mixture in the bowl until the ingredients are blended Add the contents of a boxed cake mix to the
v v v v v v v v v v v v v v v v v v v v v
mixing bowl
v v
Beat the mixture in the bowl until the ingredients are blended
v v v v v v v v v v
Pour the contents of the mixing bowl into a lightly greased cake pan Bake the cake in the oven for 45 minutes
v v v v v v v v v v v v v v v v v v v v v
4. Describe an instruction that is not well defined and thus could not be included as a step in an algorithm. Give
v v v v v v v v v v v v v v v v v v v v
an example of such an instruction.
v v v v v v
Solution:
Attempting to divide a number by 0 v v v v v v
5. In what sense is a laptop computer a general-purpose problem-solving machine?
v v v v v v v v v v
Solution:
A laptop computer is a general-purpose problem-solving machine because it is programmable and can solve
v v v v v v v v v v v v v v
any problem for which there is an algorithm.
v v v v v v v v
6. List four devices that use computers and describe the information that they process. (Hint: Think of the
v v v v v v v v v v v v v v v v
inputs and outputs of the devices.)
v v v v v v
Solution:
Digitalcamera—images, music player—sound, cell phone—text, ATM—numbers
v v v v v v
Page | 3 v v
, https://www.stuvia.com/user/Smartscroll
Page | 4
v v