B modify exercise 8a so that the premium setting

This preview shows page 24 - 30 out of 42 pages.

b. ModifyExercise 8a so that the premium-setting method calls one of twoadditional methodsone that determines the health premium or one that determinesthe auto premium. The health insurance method asks users whether they smoke; thepremium is $550 for smokers and $345 for nonsmokers. The auto insurance methodasks users to enter the number of traffic tickets they have received in the last threeyears. The premium is $225 for drivers with three or more tickets, $190 for thosewith one or two tickets, and $110 for those with no tickets. Each of these twomethods returns the premium amount to the calling method, which returns theamount to be displayed.
Programming Logic and Design, 9eSolutions 9-25Flowchart:(Please note that the main program and the getPolicyType() method are notshown in this flowchart since they remain unchanged from part a)
Programming Logic and Design, 9eSolutions 9-26Pseudocode:startDeclarationsnum policyNumnum premiumstring typenum QUIT = 999output “Enter a policy number or ”, QUIT, “ to quit”input policyNumwhile policyNum <> QUITtype = getPolicyType()premium = setPremium(type)output “The premium is ”, premiumoutput “Enter a policy number or ”, QUIT, “ to quit”input policyNumendwhilestopstring getPolicyType()Declarationsstring typeoutput “Enter the policy type (health or auto)”input typewhile type <> “health” AND type <> “auto”output “Enter the policy type (health or auto)”input typeendwhilereturn typenum setPremium(string type)Declarationsnum premiumif type = “auto” thenpremium = setAutoPremium()elsepremium = setHealthPremium()endifreturn premiumnum setAutoPremium()Declarationsnum premiumnum numTicketsoutput“Enter the number of tickets received in the last3years”input numTicketsif numTickets >= 3 thenpremium = 225elseif numTickets >= 1 thenpremium = 190elsepremium = 110endifendif
Programming Logic and Design, 9eSolutions 9-27return premiumnum setHealthPremium()Declarationsnum premiumstring doSmokeoutput“Do you smoke?”input doSmokeifdoSmoke = “Yes” thenpremium = 550elsepremium = 345endifreturn premium9.Createthe logic for a program that prompts the user for numeric values for a month,day, and year. Then pass the three variables to the following methods:
Programming Logic and Design, 9eSolutions 9-28Pseudocode:startDeclarationsnum monthnum daynum year
Programming Logic and Design, 9eSolutions 9-29output “Enter the month, day, and year”input month, day, yeardisplayUSDate(month, day, year)displayUKDate(month, day, year)displayISDate(month, day, year)

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 42 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
Subroutine, Void type

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture