Chee Jack
asked on
Does this solution solved the question? Please comment (Or may I have suggestion for a better solution)?
1. Write the pseudocode and draw the flowchart for a hotel program to determine the cost a customer has to pay for a stay based on the following pricing policy of the choice of room:
>>>Room for 1 to 2 people: RM85
>>>Room for 3 to 4 people: RM90
>>>Room for 5 to 6 people: RM120
>>>Room for > 6 people, RM125 plus charge for additional people at RM25 per person
If the customer has a membership card, there is a 20% discount. If the customer wants to pay using credit card, there is a 15% discount. A customer cannot receive both discounts. If the customer wants to pay using credit card and has a membership card, the highest discount rate will be given.
Answer these questions before you start solving the problem.
What is the output?
→Cost of customer has to pay for a stay
How many input(s) is/are needed?
→3
What is/are the input(s)?
→number of people, number of days, payment type,
What is the process (equation) to find the output?
→cost = number of days * 85
→cost = number of days * 90
→cost = number of days * 120
→additional people = number of people - 6
→cost = number of days * [125 + 25 (additional people)]
→membership card = cost * 80/100
→credit card = cost * 85/100
How many different calculation(s) is/are needed?
→7
What structure need to be used to select which is the correct calculation to use? Repetition or decision? →decision
List your test values and the answers to that test values.
→number of people = 2
→number of days = 1
→cost = 85
→payment type = cash
→total = 85
Pseudocode
Start
Get numpeople
Get numdays
If numpeople <= 2 Then
Calculate cost = numdays * 85
EndIf
If numpeople <= 4 Then
Calculate cost = numdays * 90
EndIf
If numpeople <= 6 Then
Calculate cost = numdays * 120
EndIf
If numpeople > 6 Then
Calculate extrapeople = numpeople - 6
Calculate cost = numdays * (125 + 25 (extrapeople))
EndIf
Get paymenttype
If paymenttype == cash Then
cash == cost
Print cash
EndIf
If paymenttype == membershipcard Then
membershipcard = cost * 80/100
Print membershipcard
EndIf
If paymenttype == creditcard Then
creditcard = credit card = cost * 85/100
Print membershipcard
If paymenttype = creditcard and membershipcard
Print membershipcard
EndIf
End
>>>Room for 1 to 2 people: RM85
>>>Room for 3 to 4 people: RM90
>>>Room for 5 to 6 people: RM120
>>>Room for > 6 people, RM125 plus charge for additional people at RM25 per person
If the customer has a membership card, there is a 20% discount. If the customer wants to pay using credit card, there is a 15% discount. A customer cannot receive both discounts. If the customer wants to pay using credit card and has a membership card, the highest discount rate will be given.
Answer these questions before you start solving the problem.
What is the output?
→Cost of customer has to pay for a stay
How many input(s) is/are needed?
→3
What is/are the input(s)?
→number of people, number of days, payment type,
What is the process (equation) to find the output?
→cost = number of days * 85
→cost = number of days * 90
→cost = number of days * 120
→additional people = number of people - 6
→cost = number of days * [125 + 25 (additional people)]
→membership card = cost * 80/100
→credit card = cost * 85/100
How many different calculation(s) is/are needed?
→7
What structure need to be used to select which is the correct calculation to use? Repetition or decision? →decision
List your test values and the answers to that test values.
→number of people = 2
→number of days = 1
→cost = 85
→payment type = cash
→total = 85
Pseudocode
Start
Get numpeople
Get numdays
If numpeople <= 2 Then
Calculate cost = numdays * 85
EndIf
If numpeople <= 4 Then
Calculate cost = numdays * 90
EndIf
If numpeople <= 6 Then
Calculate cost = numdays * 120
EndIf
If numpeople > 6 Then
Calculate extrapeople = numpeople - 6
Calculate cost = numdays * (125 + 25 (extrapeople))
EndIf
Get paymenttype
If paymenttype == cash Then
cash == cost
Print cash
EndIf
If paymenttype == membershipcard Then
membershipcard = cost * 80/100
Print membershipcard
EndIf
If paymenttype == creditcard Then
creditcard = credit card = cost * 85/100
Print membershipcard
If paymenttype = creditcard and membershipcard
Print membershipcard
EndIf
End
Aren't the if/end if tests in the wrong order? For example, if there will be 4 people then the if numpeople <= 2 will fail, numpeople <= 4 will pass (and cost will be calculated), but if numpeople <= 6 will also pass and cost will be calculated with a cost of 120/day. If the order were reversed (test for > 6 first, <= 6 second, <=4 third, <=2 last).
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Get numpeople
Get numdays
If numpeople <= 2 Then
Calculate cost = numdays * 85
EndIf
If numpeople <= 4 Then
Calculate cost = numdays * 90
EndIf
If numpeople <= 6 Then
Calculate cost = numdays * 120
EndIf
If numpeople > 6 Then
Calculate extrapeople = numpeople - 6
Calculate cost = numdays * (125 + 25 (extrapeople))
EndIf
Get paymenttype
If paymenttype == creditcard Then
cost = cost * 85/100
elseif paymenttype == membershipcard
cost = cost * 80/100
end if
Print cost
End