Lab 01 — First Program Lab

Unit 01 · ~45–90 min · attempt before opening the solution · Unit index

The scenario

The registrar’s office prints a simple text student ID card for every new student. You are writing the printer.

Files

File Purpose
starter/lab-01.cpp skeleton with // TODO markers — your starting point
starter/lab-01-debug-it.cpp the same program with 4 seeded bugs — part 2 of the lab
solution/lab-01-solution.cpp a complete solution — open only after your attempt

Part 1 — Build the card printer

Requirements

  1. Print a card with: a title line ==== STUDENT ID ====; your name; a programme line (e.g. BS Data Science); a year line; and a closing border of the same width as the title.
  2. Every output line ends with a newline (\n).
  3. The program compiles with zero warnings: g++ -std=c++17 -Wall -Wextra lab-01.cpp -o lab-01
  4. Use at least one chained << statement (two pieces sent in one statement) — see Lesson 2.

Expected output (shape — your details differ):

==== STUDENT ID ====
Name     : Ayesha Khan
Programme: BS Data Science
Year     : First
=====================

Method (from the Study Guide): write the steps as comments first; compile after every line; grow the program one output line at a time.

Part 2 — Debug It

Open starter/lab-01-debug-it.cpp. It looks like a working card program but contains 4 seeded bugs — a mix of compile errors and a wrong-output mistake.

Rules of the hunt

Done means: the debug file compiles warning-free and prints the card correctly, and you can say for each of the 4 bugs what it was and how the compiler told you (or didn’t, for the wrong-output bug).

Self-check (score yourself, /5)

  1. Card prints with correct shape and my details
  2. Compiles with zero warnings
  3. Used at least one chained <<
  4. All 4 Debug It bugs found, fixed, and explained in my own words
  5. My bug diary has ≥ 4 entries from this lab

Score 5/5 and quiz ≥ 90% → Unit 01 done (how scoring works).


← Unit index · Quiz 01