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, 8eSolutions 9-Pseudocode:startDeclarationsnum principalnum balanceoutput “Enter the principal amount ”input principalbalance = computeBalance(principal)output “After one year the balance is ”, balancestopnum computeBalance(num prin)Declarationsnum balancenum INTEREST_RATE = 0.02balance = prin * (1 + INTEREST_RATE)return balancec. 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, 8eSolutions 9-Answer: A sample solution followsFlowchart:Pseudocode:startDeclarationsnum principalnum interestRatenum balance10
Programming Logic and Design, 8eSolutions 9-output “Enter the principal amount ”input principaloutput “Enter the interest rate ”input interestRatebalance = computeBalance(principal, interestRate)output “After one year the balance is ”, balancestopnum computeBalance(num prin, num interest)Declarationsnum balancebalance = prin * (1 + interest)return balance4.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 followsFlowchart:11
Programming Logic and Design, 8eSolutions 9-Pseudocode:startDeclarationsnum salarynum highestPymtoutput “Enter your annual salary ”input salaryhighestPymt = calcHighestPymt(salary)output “The highest monthly payment you can afford is: ”, highestPymtstopnum calcHighestPymt(num salary)Declarationsnum paymentnum PERCENTAGE = 0.25payment = (salary * PERCENTAGE) / 12return payment12
Programming Logic and Design, 8eSolutions 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.