Capstone: own per-student mark arrays and generate results

This is an invented five-part practice case, not an assertion about the course’s unnamed comprehensive case.

Part 1: marks.txt starts with n in 0..100 and subjects in 1..10, then exactly n records: a unique id in 1..1000000 followed by subjects marks, each in 0..100. Tokens are whitespace separated decimal integers; reject missing/extra/malformed/overflowing tokens and tokens longer than 63 bytes. Choose Student { long id; int *marks; }, with one allocated Student array and a separately allocated marks array per student; do not replace this ownership exercise with a fixed matrix.

Part 2: build a loader whose every partial state can be destroyed safely, including failure allocating a later row. Explain how initializing every child pointer to NULL supports cleanup.

Part 3: write borrowing functions for total and “all marks at least 40.” A high total cannot compensate for one failed subject. Select the highest total; ties choose the smaller ID, even if the tied record occurs later.

Part 4: after complete validation and successful input close, write results.csv with header id,total,status, preserving input order and using PASS or RETAKE. Print OK students=n subjects=m best_id=id best_total=t, or OK students=0 subjects=m best=none for no students.

Part 5: handle input/memory/output failures with ERROR input, ERROR memory or ERROR output and nonzero status; close every opened stream and free all allocated rows and the table. Invalid input must preserve an existing results.csv; failed output may leave a partial file.

Use the bounded integer-token helper from the model or an equivalent overflow-aware parser. For n=3, subjects=3 and records (9,80,80,80), (7,100,100,40), (12,100,100,39), state exact stdout/results, show the tie decision and draw ownership after the second row. Test empty input, threshold 40, equal totals, a late invalid score, duplicate IDs, truncated rows and a missing file.


