Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
In the analysis stage of the cinema ticket program, the manager adds a new requirement: a group of or more people gets dollars off the total. An adult ticket costs dollars and a child ticket costs dollars. The designer changes the pseudocode to this.
INPUT Adults
INPUT Children
Total ← Adults * 9 + Children * 5
IF Adults + Children >= 10
THEN
Total ← Total - 10
ENDIF
OUTPUT TotalWork out the output for group A, adults and children, and for group B, adults and children.
The program development life cycle has four stages. Analysis: identify the problem and the requirements, with abstraction and decomposition. Design: decomposition, structure diagrams, flowcharts and pseudocode. Coding: write the program code, with iterative testing. Testing: test the whole program with test data.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Given. Adult dollars, child dollars, dollars off for or more people.
Step 1. Group A before the discount. dollars.
Step 2. Group A, the condition. people, and is true. So the total becomes dollars.
Step 3. Group B. dollars. There are people, and is false, so there is no discount.
Answer: group A pays dollars and group B pays dollars.
Check. A group of exactly must get the discount, because the condition is >=. With >, a group of would pay the full price. A requirement like "10 or more" has to be turned into exactly the right operator.
Log in to join the discussion.
Loading…