Read a scenario and plan an algorithm
From a scenario to a contract
A booking system reads a requested group size. It must accept the whole group or refuse it; refusing must not change the available seats.
| Identifier | Type | Purpose |
|---|---|---|
| Remaining | INTEGER | Available seats |
| Size | INTEGER | Requested seats |
| Accepted | BOOLEAN | Whether the request fits |
Separate the input, the decision, the state change and the output. Write down the inclusive boundary: a group using every remaining seat still fits.
Worked example: one request
Known: seven seats remain and the request is seven. Compare the request against remaining seats because accepting depends on the current capacity.
DECLARE Remaining, Size : INTEGER
Remaining ← 7
Size ← 7
IF Size <= Remaining THEN
Remaining ← Remaining - Size
OUTPUT "accepted"
ELSE
OUTPUT "rejected"
ENDIF
OUTPUT Remaining

The output is accepted, then 0. Changing Size to 8 must leave Remaining at 7. That second test checks the refused branch.
Common mistakes
- Subtracting before the test:
Remaining ← Remaining - Size, thenIF Remaining >= 0. A refused group has already taken its seats. Test first; changeRemainingonly in the accepted branch. - Writing
Size < Remaining. A group that needs exactly the seats left is wrongly refused. - Updating
RemainingafterENDIF. Then the refused branch changes the state too. - Testing only one accepted request. It says nothing about the refused branch, so test a request that is one too large.
Guided, then independent
First finish the booking algorithm. Then solve the lift problem from a blank editor. In the reasoning box, explain why an oversized request must not change the total, and trace a request that exactly reaches the limit.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
For booking seats, each request has a name, integer quantity and accepted/rejected status. Choose the types for those THREE fields in order from STRING, INTEGER, BOOLEAN, REAL.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
Finish the starter: read NumberOfGroups positive group sizes. Capacity is 15. Accept a group if it fits, output accepted/rejected, then remaining seats.
اضغط تشغيل لرؤية المخرجات هنا.
الصعوبة 3/5 · 200 عملة + مكافأة صغيرة عند الإنجاز الأول اليوم
A lift has a maximum total weight of 300. Read NumberOfPeople (1 to 5) then NumberOfPeople positive integer weights. Output the number admitted and final weight. Skip a person who would exceed 300; later people may still fit.
اضغط تشغيل لرؤية المخرجات هنا.
Explain your choice of data structure and loop. Identify one boundary case and predict its result. For a subroutine, explain what is returned or changed in the caller.
محفوظة لهذه الجلسة على هذا المتصفح. راجعها بنفسك أو مع معلمك؛ لا يتم تصحيح هذه الشرح تلقائيًا.
راجع شرحك بناءً على معايير التقييم هذه
- My types and data structure match the data and the question.
- I justified the loop and checked its first and last iterations.
- Initial values and rejected operations preserve the intended state.
- My test includes input, purpose and expected result.
- I distinguished returning a value from printing and changing caller state.