Programming Fundamentals Using C++

Project 02 · Expense Tracking System

Modules 9–12 (Weeks 9–12) · arrays as collections, parallel arrays, sorting, reports — no files, no structs yet Outcomes: CLO-6 (PF-9…PF-12). Difficulty: ★★☆☆☆ · Builds directly on P1.

1. Problem description

A student club treasurer tracks small cash expenses (canteen, transport, printing, supplies, other) during an event day. Write a console program that accepts a day's expenses, stores them in memory, and produces the reports the treasurer reads aloud at the evening meeting: totals per category, the largest expense, a sorted listing, and a category-share line.

2. Learning objectives

  1. Use arrays as collections with exact bounds discipline (n, cap).
  2. Manage parallel arrays safely — or explain why you avoided them.
  3. Implement and apply your own selection or insertion sort (L24).
  4. Produce aggregate reports (category totals, shares) from stored data.
  5. Keep validation at the input boundary so reports never see bad rows.

3. Functional requirements

4. Non-functional requirements

5. Suggested data structures

6. User interaction design

expense (cat amount | undo | done): food 12.50
expense (cat amount | undo | done): transport 45
expense (cat amount | undo | done): food 8
expense (cat amount | undo | done): done
total: 65.50
by category:
food 20.50 31.30%
transport 45.00 68.70%
printing 0.00 0.00%
supplies 0.00 0.00%
other 0.00 0.00%
largest: 45.00 (transport)
sorted: 8.00 12.50 45.00
over 100: 0

7. Input validation requirements

8. Testing plan

#ClassInputExpected
T1typicalthe session abovethe report above (shares sum ≈ 100 %)
T2tietwo 45.00 in different categorieslargest names the FIRST
T3sort5 unsorted amounts incl. equalascending line, equal values adjacent
T4boundaryamount 0.01 and 5000 acceptedboth appear; 5000.01 rejected
T5invalidsnacks 10bad category, count unchanged
T6invalidfood 0bad amount
T7undoadd 3, undo 1, reporttotal has 2 entries; undo again removes next
T8undo-emptyundo firstnothing to undo
T9capacity201 adds201st → full
T10emptydone firstno expenses

9. Milestones

  1. M1: add-phase with validation into parallel arrays + T5/T6.
  2. M2: total + by-category report + T1 (first three lines).
  3. M3: your own sort + sorted line + largest + T2/T3.
  4. M4: undo + capacity + empty cases + T7–T10.

10. Extension ideas ⚙

11. Assessment rubric (10 points when graded as homework)

PointsLine
0–3Storage + validation correct (VR1–VR3, T4–T6)
0–2Reports exact (labels, 2 dp, shares, T1)
0–2Own sort + largest + over-100 (FR3/FR4, T2/T3)
0–2Undo + capacity + empty (FR5, VR4–VR5, T7–T10)
0–1Bounds discipline visible (NFR1) + test table

Course-gate: does not compile with the contract → 0.

12. Student instructions

Work individually. The parallel-array alignment bug is the famous one — your test table MUST include a case where sorting happens before the category report (T1's order does this) to prove categories still match amounts. Deliverables: expenses.cpp, test_table.md (T1–T10), postmortem.md (one real defect narrated). Zip as p02_<yourid>.zip. std::sort or vector here = scope violation: correctness capped at 3/10 under the scope-calibration line.

Programming Fundamentals Using C++ · C++17 · 16 weeksBack to top ↑