AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content

01 C++ and the toolchain / Checkpoint

Checkpoint — C++ and the toolchain

25 min · +25 XP · 3 exercises · 15 questions

Exercises0/3
Quiz · 70% to clear15 q

This checkpoint covers the whole module: what C++ is and the decisions behind it, the four-stage pipeline from source to executable, the anatomy of a program, console input and output, and reading what the compiler says.

How it works. Fifteen questions and three programs. You need 70% on the questions and every program accepted to clear the module. You can retake it as often as you like; your best score counts.

Before you start, make sure you can answer these from memory:

  • Which stage of the build turns #include into text, and which one reports undefined reference?
  • What is a translation unit, and why is a header never compiled on its own?
  • What does main return when it falls off its closing brace, and what does a non-zero exit code mean to the judge?
  • Why does std::getline right after std::cin >> n return an empty line, and what is the fix?
  • How does while (std::cin >> x) know when to stop?
  • What is the difference between '\n' and std::endl?

The three programs use lesson 4's reading patterns — a token, lines until the input ends, and a count followed by alternating lines and tokens. Read each input format carefully; most failed submissions here are reading problems, not logic problems.

Common questions

Which build stage reports undefined reference?

The linker. The preprocessor turns #include into pasted text and the compiler checks each translation unit on its own; only the linker notices that a declared and used symbol has no definition in any object file.

What does main return when it has no return statement?

main alone may fall off its closing brace, and doing so returns 0, which means success. Any non-zero exit code means failure, and a judge marks it as a runtime error even when the printed output is right.

How does while (std::cin >> x) know when to stop?

std::cin >> x returns the stream, and a stream converts to false once a read has failed — at the end of the input, or on text that cannot form the value. The loop therefore ends exactly when the input does, with no count or sentinel needed.

C++ Basics Quiz: Compiling, Linking and Console I/O Practice

Test your C++ fundamentals with 15 questions and three programs on the compile and link pipeline, program structure, cin and getline, and compiler errors.

  • Course: C++ study plan
  • Module: C++ and the toolchain
  • Kind: Checkpoint — cleared at 70%
  • Reading time: 25 min
  • Runtime: Clang 18 · C++20

Checkpoint — C++ and the toolchain is the checkpoint that closes the C++ and the toolchain module: a graded quiz and whole-program exercises, passed at 70%.

Instructions

This checkpoint covers the whole module: what C++ is and the decisions behind it, the four-stage pipeline from source to executable, the anatomy of a program, console input and output, and reading what the compiler says.

How it works. Fifteen questions and three programs. You need 70% on the questions and every program accepted to clear the module. You can retake it as often as you like; your best score counts.

Before you start, make sure you can answer these from memory:

  • Which stage of the build turns #include into text, and which one reports undefined reference?
  • What is a translation unit, and why is a header never compiled on its own?
  • What does main return when it falls off its closing brace, and what does a non-zero exit code mean to the judge?
  • Why does std::getline right after std::cin >> n return an empty line, and what is the fix?
  • How does while (std::cin >> x) know when to stop?
  • What is the difference between '\n' and std::endl?

The three programs use lesson 4's reading patterns — a token, lines until the input ends, and a count followed by alternating lines and tokens. Read each input format carefully; most failed submissions here are reading problems, not logic problems.

Common questions

Which build stage reports undefined reference?

The linker. The preprocessor turns #include into pasted text and the compiler checks each translation unit on its own; only the linker notices that a declared and used symbol has no definition in any object file.

What does main return when it has no return statement?

main alone may fall off its closing brace, and doing so returns 0, which means success. Any non-zero exit code means failure, and a judge marks it as a runtime error even when the printed output is right.

How does while (std::cin >> x) know when to stop?

std::cin >> x returns the stream, and a stream converts to false once a read has failed — at the end of the input, or on text that cannot form the value. The loop therefore ends exactly when the input does, with no count or sentinel needed.

Exercises

Multiplication table

Read an integer n (1 ≤ n ≤ 12) and print the multiplication table for 1 through n: row i contains i×1, i×2, …, i×n, each number right-aligned in a field of width 4, with no trailing text.

Input: n. Output: n lines of n numbers.

Use std::setw(4) from <iomanip> before each number; it applies to the next value only.

Example: n = 3 →

   1   2   3
   2   4   6
   3   6   9

Word count

Implement a tiny wc: read all of standard input until it ends and print three lines — the number of lines, the number of words (whitespace-separated tokens) and the number of characters, counting every character including spaces and the newline that ends each line.

Input: zero or more lines, each ending in a newline. Output: lines=<l>, words=<w>, chars=<c>.

Use while (std::getline(std::cin, line)); every line read counts as one line and contributes its length plus one. Count the words on a line by wrapping it in a std::istringstream and extracting with >> until that fails.

Example: input

the quick brown
fox

→

lines=2
words=4
chars=20

Student report

Read an integer n, then n students. Each student takes two lines: the name (which may contain spaces), then a count k (at least 1) followed by k integer marks on the same line. Print one line per student, <name>: <sum> (<average>) with the average fixed to two decimals, then top: <name> for the student with the highest average — the first such student if several tie.

Input: n, then n pairs of lines. Output: n report lines, then the top: line.

This mixes every reading pattern: >> for n, std::cin.ignore() before the first std::getline, getline for the name, >> for the marks, and ignore() again before the next name.

Example: input

2
Ada Lovelace
3 90 80 70
Alan Turing
2 100 95

→

Ada Lovelace: 240 (80.00)
Alan Turing: 195 (97.50)
top: Alan Turing

In this module: C++ and the toolchain

← Compilers, warnings and reading error messages · The fundamental types — bool, char, integers and floating point →