Foundations

The parts of a C++ program, the types of its values, reading and formatting data, and how programs choose and repeat.

About 10 hours of study

Learning objectives

Lessons

  1. 1

    Your first C++ program

    The parts of a C++ program, printing with cout, reading with cin, and what namespaces are for.

  2. 2

    Variables and types in C++

    Store values in variables, choose among int, double, char, bool and string, use const and auto, and convert between types safely.

  3. 3

    Input and output in depth

    Read whole lines with getline, read until the input ends, and format output in columns with iomanip.

  4. 4

    Decisions and loops

    Choose with if and switch, repeat with for and while, and control a loop with break and continue.

Module practice

Module quiz

1. What does cout << 7 / 2; print when both are ints?
2. Why does getline after cin >> n often read an empty line?
3. Which setting applies only to the next value printed?
4. What does auto x = 3 / 2.0; make x?
5. What is wrong with if (a = b)?
6. What does while (cin >> x) do when the input ends?

Functions and everyday data ›