Programming Logic and Design 8e Solutions 9 Pseudocode start Declarations num

# Programming logic and design 8e solutions 9

• Homework Help
• 46
• 97% (175) 169 out of 175 people found this document helpful

This preview shows page 18 - 25 out of 46 pages.

18
Programming Logic and Design, 8e Solutions 9- Pseudocode: start Declarations num price num commission num discount num finalPrice input price, commission, discount finalPrice = calculatePrice(price, commission, discount) output finalPrice stop num calculatePrice(num price, num comm, num disc) Declarations num total num finalPrice total = price * (1 + (comm / 100)) finalPrice = total * (1 – (disc / 100)) return finalPrice 19
Programming Logic and Design, 8e Solutions 9- 8.Create the logic for a program that continuously prompts the user for two numeric values that represent the dimensions of a room in feet. Include two overloaded methods that compute the room’s area. One method takes two numeric parameters 20
Programming Logic and Design, 8e Solutions 9- Pseudocode: start Declarations num length num width output “Enter a value for the length, or zero to quit” input length 21
Programming Logic and Design, 8e Solutions 9- while length < 0 output “Please reenter a value for the length” input length endwhile if length > 0 then output “Enter a value for the width” input width while width < 0 output “Please reenter the value for the width” input width endwhile if width > 0 then calcArea(length, width) else calcArea(length) endif endif stop void calcArea(num side) Declarations num area area = side * side output “The area is ”, area return void calcArea(num side1, num side2) Declarations num area area = side1 * side2 output “The area is ”, area return 9.a. Plan the logic for an insurance company program to determine policy premiums. The program continuously prompts the user for an insurance policy number. When the user enters an appropriate sentinel value, end the program. Call a method that prompts each user for the type of policy needed—health or auto. While the user’s response does not indicate health or auto, continue to prompt the user. When the valueis valid, return it from the method. Pass the user’s response to a new method where the premium is set and returned—\$550 for a health policy or \$225 for an auto policy. Display the results for each policy. 22
Programming Logic and Design, 8e Solutions 9- Pseudocode: start Declarations num policyNum num premium string type num QUIT = 999 output “Enter a policy number or ”, QUIT, “ to quit” input policyNum while policyNum <> QUIT type = getPolicyType() premium = setPremium(type) 23
Programming Logic and Design, 8e