ITPEC FE Subject B October 2024 Question 2
ITPEC FE Subject B October 2024 — Question 2 of 20
Array Manipulation — filling in blanks for a function that checks product ID's last digit and calculates coupon count.
The function gives 1 coupon per every 3 purchased products, but only if the product ID ends in 3.
Blank A — checking the last digit:
- The last digit of an integer is obtained by prod_id mod 10
- The condition checks prod_id mod 10 = 3
- Options a–c use integer part of (prod_id ÷ 10), which removes the last digit instead of extracting it
- Options d–f compare prod_id to 10 mod 3 = 1, which is meaningless
Blank B — number of coupons:
- "For every purchase of three products → one coupon" means integer division by 3
- integer part of (pur_prod ÷ 3) = floor(pur_prod / 3)
- Example: pur_prod = 7 → floor(7/3) = 2 coupons
Why not others:
- (a–c) integer part of (prod_id ÷ 10) = 3 checks if the tens digit is 3, not the last digit
- (d–f) prod_id = 10 mod 3 compares prod_id to 1, not a valid last-digit check
- (h) + 1 would give an extra coupon (e.g., 3 items → 2 coupons instead of 1)
- (i) pur_prod mod 3 gives the remainder, not the number of complete groups of 3
Key rule: To extract the last digit of an integer, use number mod 10. To count how many complete groups of N fit, use integer part of (number ÷ N).
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
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 FE past-paper collection or Report an issue.