ITPEC IP October 2025 Question 6

At a certain company, employees get a medical allowance equal to 5% of their monthly base salary in addition to their monthly base salary. If the total of the monthly base salary and medical allowance is more than 5,000, a 20% tax is deducted from the total. In the program below, the function calculateTotalSal receives the monthly base salary as an argument and returns the monthly total salary after tax deduction. Which of the following is the correct combination of pieces of code to be inserted into A and B in the program? Here, the monthly base salary is a multiple of 100.

[Program]
○ integer: calculateTotalSal(integer: monthlyBaseSal)
integer: monthlyTotalSal
monthlyTotalSal ← integer part of (monthlyBaseSal × 1.05)
if (monthlyTotalSal > A)
monthlyTotalSal ← integer part of (monthlyTotalSal × B)
endif
return monthlyTotalSal
OptionAB

Explanation

A: 5000, B: 0.8 — the tax test uses the total that already includes the allowance, and a 20% tax leaves 80% of it.

  • •The first assignment already makes monthlyTotalSal the base salary plus the 5% allowance, base × 1.05
  • •The rule taxes that total when it is more than 5,000, so the condition is monthlyTotalSal > 5000
  • •Deducting 20% keeps 100% − 20% = 80%, so the total is multiplied by 0.8

Check with a base of 4,800: the total is 4800 × 1.05 = 5040, more than 5,000, so the result is 5040 × 0.8 = 4032.

Answer (b)

Why not others:

  • •(a) — multiplying by 0.2 returns the 20% tax itself, 1,008 in the example, not the salary left after it
  • •(c) and (d) — 5250 is 5000 × 1.05, the total for a base of exactly 5,000: it puts the 5,000 limit on the base salary instead of the total, so a total of 5,040 would escape the tax; (c) also returns the tax amount

Key rule: Check which value a condition tests after the earlier assignments have run, and multiply by what remains, 1 minus the rate, when a rate is deducted.

Algorithm and Programming · AI-written, may contain errors

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official IP past-paper collection or Report an issue.