Chapter 4
Exercises
2. Chocolate Delights Candy Company manufactures several types of candy. Design a flowchart or pseudocode for the following:
a. A program that accepts a candy name (for example, “chocolate-covered blueberries”), price per pound, and number of pounds sold in the average month, and displays the item’s data only if it is a best-selling item. Best-selling items are those that sell more than 2,000 pounds per month.
Answer:
A sample solution is as follows:
Pseudocode:
start Declarations string name double pricePerPound double poundsSold double POUNDS_MIN = 2000 display “Enter the name of the candy: ” get name display “Enter the price per pound of this candy in Dollars: ” get pricePerPound display “Enter the number of pounds of this candy that was sold: ” get poundsSold if poundsSold > POUNDS_MIN then display “This is a best selling candy! Name: “, name, “Price per pound: “, pricePerPound, “Pounds sold:”, poundsSold endif stop Flowchart:
4. The Summerville Telephone Company charges 10 cents per minute for all calls outside the customer’s area code that last over 20 minutes. All other calls are 13 cents per minute. Design a flowchart or pseudocode for following:
a. A program that accepts data about one phone call: customer area code (three digits), customer phone number (seven digits), called area code (three digits), called number (seven digits), and call time in minutes (four digits). Display the calling number, called number, and price for the call.
Answer:
A sample solution is as follows:
Pseudocode:
start Declarations int custAreaCode int custPhoneInt int calledAreaCode int calledPhoneInt int minutes int price int LOW_RATE = 0.10 int HIGH_RATE = 0.13 int TIME_LIMIT = 20 display “Enter customer area code: ” get custAreaCode display “Enter customer phone