N productname brush not valid string constant must

This preview shows page 7 - 12 out of 36 pages.

n. productName = brush Not valid. String constant must appear within quotes. o. battery = productName Not valid. Value on left is not a declared variable. p. productPrice = productPrice Valid, but trivial. q. productName = productCost Valid. 3.Assume that speed = 10and miles = 5. What is the value of each of the following expressions?Answer: a.speed + 12 - miles * 212b.speed + miles * 325c.(speed + miles) * 345d.speed + speed * miles + miles65e.(10 – speed) + miles / miles1 4. Draw a typical hierarchy chart for a program that produces a monthly bill for a cell phone customer. Try to think of at least 10 separate modules that might be included. For example, one module might calculate the charge for daytime phone minutes used. Answer : produceCellPhoneBill() getUsageInfo() getCustomerInfo() printBill() calcLocalTax() calcFedTax() computeTextFee() computeCallFee() calcStateTax() computeTaxes() getNightMins() getDaytimeMins()
Programming Logic and Design, 9e Solutions 2-8 5. a. Draw the hierarchy chart and then plan the logic for a program needed by Hometown Bank. The program determines a monthly checking account fee. Input includes an account balance and the number of times the account was overdrawn. The output is the fee, which is 1 percent of the balance minus 5 dollars for each time the account was overdrawn. 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 balances. The detail module prompts for and accepts the number of overdrafts, computes the fee, and displays the result. The end- of-job module displays the message Thanks for using this program . Answer : A sample solution is as follows: a. Hierarchy chart : Flowchart: main program housekeeping() detail() endOfJob()
Programming Logic and Design, 9e Solutions 2-9 Pseudocode: start Declarations num balance num numOverdrafts num fee string BALANCE_PROMPT = “Enter the balance: ” string OVERDRAFT_PROMPT = “Enter the number of overdrafts: ” string END_LINE = “Thanks for using this program” housekeeping() detail() endOfJob() stop housekeeping() output BALANCE_PROMPT input balance return detail() output OVERDRAFT_PROMPT input numOverdrafts fee = (0.01 * balance) – (5 * numOverdrafts) output fee return endOfJob() output END_LINE
Programming Logic and Design, 9e Solutions 2-10 return b. Revise the banking program so that it runs continuously for any number of accounts. The detail loop executes continuously while the balance entered is not negative; in addition to calculating the fee, it prompts the user for and gets the balance for the next account. The end-of-job module executes after a number less than 0 is entered for the account balance. Answer : A sample solution is as follows: b. Hierarchy chart : Flowchart: main program housekeeping() detailLoop() endOfJob()
Programming Logic and Design, 9e Solutions 2-11 Pseudocode: start Declarations num balance num numOverdrafts num fee string BALANCE_PROMPT = “Enter the balance: ” string OVERDRAFT_PROMPT = “Enter the number of overdrafts: ” string END_LINE = “Thanks for using this program” housekeeping() while balance >= 0 detailLoop() endwhile endOfJob() stop housekeeping() output BALANCE_PROMPT input balance return detailLoop() output OVERDRAFT_PROMPT

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture