The Fee-Defaulter List That Counted Wrong
The IT club has 30 students registered for a hardware workshop. The fee is Rs 150. A student with a sibling also registered pays Rs 100. A student who has not paid is a defaulter; if the sibling concession applies, the amount still due is Rs 100 instead of Rs 150. The club writes this pseudocode:
total = 0 count = 0 for i = 1 to 30 read paid[i], sibling[i] if paid[i] = "yes" OR sibling[i] = "yes" then amount = 100 else amount = 150 end if total = amount count = count + 1 end for print "Total collected", total
The treasurer tests it on four students: (1) paid yes, no sibling; (2) paid yes, sibling yes; (3) paid no, sibling yes; (4) paid no, no sibling. The expected total collected is Rs 250, and the club needs a list of defaulters with the amount each still owes. The program prints Rs 150 and no list.
1. Trace the pseudocode for the four test students and show exactly why it prints 150. Then identify three separate logic errors in the pseudocode.
Read the worked answer
Trace: student 1 has paid = yes, so the OR condition is true, amount becomes 100, and total is set to 100. Student 2 has paid = yes and sibling = yes, so amount is 100 and total is set to 100 again. Student 3 has paid = no but sibling = yes, so the OR condition is true, amount is 100, and total is set to 100 again. Student 4 has paid = no and sibling = no, so amount is 150 and total is set to 150. The loop ends and prints 150. The total never accumulates because each pass overwrites it.
Error one: total = amount should be total = total + amount. Error two: the OR condition applies the concession to a student who paid but has no sibling (student 1) and treats a non-paying sibling student as if the concession settles the fee. The concession should require paid = yes AND sibling = yes for the amount collected; a non-paying student with a sibling still owes the concession amount. Error three: the program never checks paid = no, so it cannot build the defaulter list or the amount due. A fourth weakness is that count counts every student, not just payers, but it is not printed.
2. Rewrite the pseudocode correctly. Your version must add only money actually paid to total collected, apply the concession only when the student has paid and has a sibling, and print each defaulter's name with the amount due. Explain how you would test it with the four students.
Read the worked answer
A correct version:
total = 0
for i = 1 to 30
read name[i], paid[i], sibling[i]
if paid[i] = "yes" then
if sibling[i] = "yes" then
total = total + 100
else
total = total + 150
end if
else
if sibling[i] = "yes" then
due = 100
else
due = 150
end if
print name[i], "owes", due
end if
end for
print "Total collected", total
The outer test separates money received from money still owed. The inner test applies the concession only to a payer with a sibling, and separately sets the lower amount due for a non-payer with a sibling. Test expectations: student 1 adds 150; student 2 adds 100, so total collected is 250; student 3 is printed as owing 100; student 4 is printed as owing 150. The printed total is 250, matching the expected figure. I would also test a paid student with a sibling but no registered sibling record, a blank name, and a non-payer with a sibling who is not actually registered; these should be rejected or flagged, not silently given the concession.
3. The club wants to collect sibling information only from students who ask for the concession, to reduce data collection. Explain how this changes the input order or validation, and state one privacy rule for storing sibling names.
Read the worked answer
The input order should change from reading sibling data for all 30 students to a two-step process. First read name and paid status for everyone. Then ask a single question: 'Are you claiming the sibling concession?' Only if the answer is yes should the program ask for the sibling's name and roll number. Validation should check that the sibling is also registered for the workshop, that the student is not naming themselves, that the pair has not already claimed the concession twice, and that the claimed sibling record exists. A student who has not paid can still claim the concession, but the programme must record the amount due, not mark the fee as paid. If the sibling details fail validation, the student should be charged the full Rs 150 until the office verifies the claim.
One privacy rule: store sibling names only in the fee register, not in the class group or a public spreadsheet, and give access only to the treasurer and teacher. Delete or archive the sibling details after the workshop accounts are closed. Collecting less data reduces the harm if the file is shared accidentally, and it is fairer to students who are not claiming the concession.