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 8 - 15 out of 46 pages.

Programming Logic and Design, 8e Solutions 9- Pseudocode: start Declarations num principal num balance output “Enter the principal amount ” input principal balance = computeBalance(principal) output “After one year the balance is ”, balance stop num computeBalance(num prin) Declarations num balance num INTEREST_RATE = 0.02 balance = prin * (1 + INTEREST_RATE) return balance c. Modify the program in Exercise 3b so that the main program also prompts the user for the interest rate and passes both the amount of money and the interest rate to the interest-calculating method. 9
Programming Logic and Design, 8e Solutions 9- Answer: A sample solution follows Flowchart: Pseudocode: start Declarations num principal num interestRate num balance 10
Programming Logic and Design, 8e Solutions 9- output “Enter the principal amount ” input principal output “Enter the interest rate ” input interestRate balance = computeBalance(principal, interestRate) output “After one year the balance is ”, balance stop num computeBalance(num prin, num interest) Declarations num balance balance = prin * (1 + interest) return balance 4. Create the logic for a program that accepts an annual salary as input. Pass the salary to a method that calculates the highest monthly housing payment the user can afford, assuming that the year’s total payment is no more than 25 percent of the annual salary. Answer: A sample solution follows Flowchart: 11
Programming Logic and Design, 8e Solutions 9- Pseudocode: start Declarations num salary num highestPymt output “Enter your annual salary ” input salary highestPymt = calcHighestPymt(salary) output “The highest monthly payment you can afford is: ”, highestPymt stop num calcHighestPymt(num salary) Declarations num payment num PERCENTAGE = 0.25 payment = (salary * PERCENTAGE) / 12 return payment 12
Programming Logic and Design, 8e Solutions 9-5.a. Create the logic for a program that performs arithmetic functions. Design the program to contain two numeric variables, and prompt the user for values for the variables. Pass both variables to methods named sum()and difference()Create the logic for the methods sum()and difference(); they compute the sum of and difference between the values of two arguments, respectively. Each method should perform the appropriate computation and display the results.13 .
Programming Logic and Design, 8e