Exercises
1. Explain why each of the following names does or does not seem like a good variable name to you.
a. c –
b. cost –
c. costAmount –
d. cost amount
–
e. cstofdngbsns –
f. costOfDoingBusinessThisFiscalYear –
g. costYear2012 –
h.
2012YearCost
–
2. Assume that cost = 10 and price = 12. What is the value of each of the following expressions?
a. price – cost * 2
b.
15 + price – 3 * 2
c.
(price + cost) * 3
d.
4 – 3 * 2 + cost
e. cost * ((price – 8) + 5) + 100
3. Draw a typical hierarchy chart for a paycheck-producing program. Try to think of at least 6 separate modules that might be included. (Hint: You could have one module might calculate an employee’s dental insurance premium, you will need others to calculate federal and state taxes, and others to provide housekeeping, processing functionality, and output printing.)
4. Draw the hierarchy chart and flowchart(s) that map the logic for a program for the sales manager of The Couch Potato Furniture Company. The manager needs a program to determine the profit on any item sold. Input includes the wholesale price and retail price for an item. The output is the item’s profit, which is the retail price minus the wholesale price. Use three modules. The main program declares global variables and calls housekeeping, detail, and end-of-job modules. The housekeeping module prompts for and accepts a wholesale price. The detail module prompts for and accepts the retail price, computes the profit, and displays the result. The end-of-job module displays the message “Thanks for using this program”.
5. Create pseudocode that shows the logic for a program that generates a random number, then asks the user to think of a number between 1 and 10. Then display the randomly