Programming Logic and Design, 9th Edition. Chapter 1
Programming Logic and Design, 9th Edition. Chapter 1
Chapter 1
Review Questions
a. data
b. hardware
c. software
d. information
3. Visual Basic, C++, and Java are all examples of computer ____________.
a. operating systems
b. programming languages
c. hardware
d. machine languages
a. syntax
b. logic
c. format
d. options
Programming Logic and Design, 9e Solutions 1-2
a. CPU
b. hard disk
c. keyboard
d. memory
7. Which of the following pairs of steps in the programming process is in the correct
order?
____________.
9. The two most commonly used tools for planning a program’s logic are _____.
Programming Logic and Design, 9e Solutions 1-3
10. Writing a program in a language such as C++ or Java is known as _______ the
program.
a. translating
b. coding
c. interpreting
d. compiling
programming language.
a. machine-level
b. low-level
c. high-level
d. binary-level
a. input
b. output
c. either a or b
a. input
b. a sentinel
c. a question
d. processing
a. parallelogram
b. rectangle
c. lozenge
d. diamond
18. When you use an IDE instead of a simple text editor to develop a program,
____________.
19. When you write a program that will run in a GUI environment as opposed to a
____________.
Programming Exercises
1. Match the definition with the appropriate term.
1. Computer system devices a. compiler
2. Another word for program b. syntax
3. Language rules c. logic
4. Order of instructions d. hardware
5. Language translator e. software
Answer:
1. Computer system equipment → d. hardware
2. Another word for program → e. software
3. Language rules → b. syntax
4. Order of instructions → c. logic
5. Language translator → a. compiler
Answer:
The programmer must understand the problem that the user is trying to solve. Next,
the programmer plans the logic, often using a flowchart or pseudocode. Then, the
program is coded in a language, such as Visual Basic or Java, and translated to
machine language using a compiler or interpreter. Finally, the program is tested and
then put into production and maintained over the ensuing months or years.
Answer:
Flowchart
Programming Logic and Design, 9e Solutions 1-7
Pseudocode
start
input myNumber
myAnswer = myNumber * 10
output myAnswer
stop
4. Draw a flowchart or write pseudocode to represent the logic of a program that allows
the user to enter a value for one edge of a cube. The program calculates the surface
area of one side of the cube, the surface area of the cube, and its volume. The
program outputs all the results.
Answer:
Flowchart
Programming Logic and Design, 9e Solutions 1-8
Pseudocode
start
input edge
sideArea = edge * edge
surfaceArea = 6 * sideArea
volume = edge * edge * edge
output sideArea
output surfaceArea
output volume
stop
Programming Logic and Design, 9e Solutions 1-9
5. Draw a flowchart or write pseudocode to represent the logic of a program that allows
the user to enter a value for hours worked in a day. The program calculates the hours
worked in a five-day week and the hours worked in a 252-day work year. The
program outputs all the results.
Answer:
Flowchart
Pseudocode
start
input hoursWorkedDay
hoursWorkedWeek = hoursWorkedDay * 5
hoursWorkedYear = hoursWorkedDay * 252
output hoursWorkedWeek
output hoursWorkedYear
stop
6. Draw a flowchart or write pseudocode to represent the logic of a program that allows
the user to enter two values. The program outputs the sum of and the difference
between the two values.
Programming Logic and Design, 9e Solutions 1-10
Answer:
Flowchart
Pseudocode
start
input firstValue
input secondValue
sum = firstValue + secondValue
difference = secondValue - firstValue
output sum
output difference
stop
7. Draw a flowchart or write pseudocode to represent the logic of a program that allows
the user to enter values for the current year and the user’s birth year. The program
outputs the age of the user this year.
Answer:
Programming Logic and Design, 9e Solutions 1-11
Flowchart
Pseudocode
start
input currentYear
input birthYear
age = currentYear - birthYear
output age
stop
Answer:
Flowchart
Programming Logic and Design, 9e Solutions 1-12
Pseudocode
start
input hourlyRate
input hoursWorked
grossPay = hourlyRate * hoursWorked
output grossPay
stop
b. Modify the program that computes gross pay to allow the user to enter the
withholding tax rate. The program outputs the net pay after taxes have been withheld.
Answer:
Flowchart
Programming Logic and Design, 9e Solutions 1-13
Pseudocode
start
input hourlyRate
input hoursWorked
input withholdingRate
grossPay = hourlyRate * hoursWorked
withholdAmt = grossPay * withholdingRate
netPay = grossPay - withholdAmt
output netPay
stop
Programming Logic and Design, 9e Solutions 1-14
Answer:
Flowchart
Pseudocode
start
input numDollars
numEuros = numDollars * 0.90
numYen = numDollars * 110.90
output numEuros, numYen
stop
10. A mobile phone app allows a user to press a button that starts a timer that counts
seconds. When the user presses the button again, the timer stops. Draw a flowchart or
write pseudocode that accepts the elapsed time in seconds and displays the value in
minutes and remaining seconds. For example, if the elapsed time was 130 seconds,
the output would be 2 minutes and 10 seconds.
Programming Logic and Design, 9e Solutions 1-15
Answer: (Please note this solution assumes minutes is an integer and has been truncated.)
Flowchart
Pseudocode
start
input elapsedTime
minutes = elapsedTime / 60
seconds = elapsedTime – (minutes * 60)
output minutes, seconds
stop
Performing Maintenance
1. In this chapter you learned that some of the tasks assigned to new programmers
frequently involve maintenance—making changes to existing programs because of
new requirements. A file named MAINTENANCE01-01.txt is included with your
downloadable student files. Assume that this program is a working program in your
organization and that it needs modifications as described in the comments (lines that
begin with two slashes) at the beginning of the file. Your job is to alter the program to
meet the new specifications.
Programming Logic and Design, 9e Solutions 1-16
Answer:
start
input pay
input rent
input utilities
input groceries
bills = rent + utilities + groceries
discretionary = pay - bills
output pay
output bills
output discretionary
stop
Answer:
DEBUG01-01
// This pseudocode is intended to describe
// computing the price of an item on sale for 10% off
start
input origPrice
discount = origPrice * 0.10
finalPrice = origPrice - discount
output finalPrice
stop
DEBUG01-02
// This pseudocode is intended to compute the number
// of miles per gallon you get with your automobile.
start
input milesTraveled
input gallonsOfGasUsed
milesPerGallon = milesTraveled / gallonsOfGasUsed
Programming Logic and Design, 9e Solutions 1-17
DEBUG01-03
// This pseudocode is intended to describe
// computing the per day cost of your rent
// in a 30-day month
start
input rent
costPerDay = rent / 30
// Comment indicates 30-day month
output costPerDay
// output should be costPerDay
stop
2. Your downloadable files for Chapter 1 include a file named DEBUG01-04.jpg that
contains a flowchart that contains syntax and/or logical errors. Examine the flowchart
and then find and correct all the bugs.
Answer:
Game Zone
1. Create the logic for a Mad Lib program that accepts five words from input, then
creates and displays a short story or nursery rhyme that uses them.
Programming Logic and Design, 9e Solutions 1-18
Answer:
start
input word1
input word2
input word3
input word4
input word5
output “Jack and Jill went up the ”, word1,
“ to fetch a pail of ”, word2,
“. “Jack ”, word3, “ down and broke his ”, word4,
“ and Jill came ”, word5, “ after.”
stop
Programming Logic and Design, 9e Solutions 1-19
C++
#include <iostream>
using namespace std;
int main()
{
cout << "I'm learning how to program in C++." << endl;
cout << "That's Awesome!" << endl;
return 0;
}
#include <iostream>
int main()
{
cout << "I'm learning how to program in C++." << endl;
cout << "That's awesome!" << endl;
return 0;
}
Java
public class Awesome
{
public static void main(String args[])
{
System.out.println("I am learning how to program in Java.");
System.out.println("That's awesome!");
}
}
Python
print("I'm learning how to program in Python.")
print("That's awesome!")