Skip to content

Quiz 16 — Advanced OOP and the Capstone

Ten questions on multi-file layout, the One Definition Rule, persistence boundaries and what "finished" means.

Attempt all of them closed-book, then mark yourself against the answers.

Concepts: translation units · the One Definition Rule · include guards · multi-file layout · persistence boundaries · dependency direction · capstone readiness.


Q1. (MCQ) The One Definition Rule says that across a whole program, a non-inline function or object must be:

  • A. declared exactly once
  • B. defined exactly once
  • C. defined in every file that uses it
  • D. defined in a .cpp only

Q2. (true/false) inline on a function in a header allows that function's definition to appear in several translation units.

Q3. (multiple-select) Which belong in a header, and which in a .cpp? Select the ones that belong in the header.

  • A. A class declaration
  • B. A function template's definition
  • C. A large function's implementation used by one .cpp
  • D. An inline function used by several .cpp files

Q4. (predict) Write the output.

#include <iostream>

class Counter {
public:
    int next() { return ++count_; }
private:
    int count_ = 0;
};

int main() {
    Counter c;
    std::cout << c.next() << ' ' << c.next() << '\n';
}

Q5. (debug) A header without an include guard is included twice in one translation unit. What error results, and what is the fix?

// shapes.h
struct Colour { int r = 0, g = 0, b = 0; };

// main.cpp
#include "shapes.h"
#include "shapes.h"      // included again
int main() { Colour c; }

Q6. (analysis) Why should the domain types not know the file format used for persistence? Name the layer that should, and why that direction matters for testing.

Q7. (analysis) A global variable is defined (not just declared) in a header included by three translation units. Describe the link-time error and give two fixes.

Q8. (short answer) State the dependency direction in a well-layered application, and why it points that way.

Q9. (design) A workshop system has equipment, members, loans and maintenance, must persist to a file, and must be testable module by module. State the layers, which one knows the file format, and one interface that lets a module be tested with a fake.

Q10. (design) List three things your capstone needs before you would call it finished, other than "it compiles".


Scoring: mark yourself with the answers, then read the self-assessment guide.