Skip to content
Topos Uranos

Summary

This lesson opens the eighth and last unit of the course, devoted to larger programs. It explains its purpose: to organize, verify and debug programs that no longer fit in one file or in one's head; it presents its three lessons and the thread that joins them, which closes the circle opened in the first lesson of the course (specify, build, verify); it recalls what the unit takes for granted, which is the whole course; it states the problem the unit solves, that of a single-file program that works with the data it was tested with and keeps silent about a defect at the boundary of its specification; it anticipates the difference between testing and proving; and it shows where it leads, in the final project and in Programming in C++ II.

Learning objectives

  1. Describe the sequence of contents of the unit and explain what each lesson contributes to the next.
  2. Recall, with an example, the difference between declaring and defining a function, the contract that specifies it and the stages (compilation and linking) that turn several files into a program.
  3. Anticipate, with an example, the difference between testing a program with some cases and proving that it is correct for all admissible ones.
  4. Recognize what one is expected to be able to do at the end of the unit and of the course, and distinguish it from what will be learned in Programming in C++ II.

Entry assessment

Before working through the unit, it is worth measuring the starting point. This assessment is not graded: it guides your study. The first seven questions check what the unit takes for granted (declaring and defining, the precondition, the contract of a function from unit 6, the linker messages, the cases of a binary search, the trace table and reading outside a vector); the next three touch, in the order of the lessons, on the central ideas of the unit, and in them “I don’t know yet” is an honest answer. Each answer explains the point and names the lesson that deals with it; the same skills are measured again in the synthesis lesson.

Entry assessment

Before starting the unit, measure your starting point. It is a short self-assessment: it is not graded and its result is stored only in your browser.

  1. Question 1From earlier unitsWhat does the line int gcd(int a, int b); written before main do?

  2. Question 2From earlier unitsThe function toBase(n, base) has the precondition “n >= 0 and 2 <= base <= 10”. Who must guarantee it?

  3. Question 3From earlier unitsThe function binarySearch(values, target) of lesson 6.4 returns a position of target, or values.size() if it is not there. What is its precondition?

  4. Question 4From earlier unitsA program compiles without errors and, when the executable is built, undefined reference to `tetrahedral(int)' appears. Which stage failed?

  5. Question 5From earlier unitsWhich of these sets of cases best puts a binary search to the test?

  6. Question 6From earlier unitsWhat are the values of a and b after int a{0}; int b{1}; for (int i{0}; i < 4; ++i) { const int t{a + b}; a = b; b = t; }?

  7. Question 7From earlier unitsWhy does std::vector<int> v{1, 2}; std::println("{}", v[2]); stop with the course options and, compiled only with -O2, without the sanitizers, possibly print an arbitrary number?

  8. Question 8A header with include guards defines (not merely declares) double scale(double x), without inline, and both main.cpp and report.cpp include it. What happens when the program is built?

  9. Question 9A function passes five hundred carefully chosen automated tests. What can be asserted?

  10. Question 10A breakpoint is on the line total += k;, inside a loop, and the program stops there for the third time. What does the highlighted line indicate?