I suspect you already have some knowledge of C++. Maybe you already know C, Java, Perl, or other C-like languages.
Maybe you know so many languages that you can readily identify common elements.
Take a few minutes to read the code below, and then answer the questions that follow it.
1 /// Read the program and determine what the program does.
2
3 #include <iostream>
4 #include <limits>
5
6 int main()
7 {
8 int min{std::numeric_limits<int>::max()};
9 int max{std::numeric_limits<int>::min()};
10 bool any{false};
11 int x;
12 while (std::cin >> x)
13 {
14 any = true;
15 if (x < min)
16 min = x;
17 if (x > max)
18 max = x;
19 }
20
21 if (any)
22 std::cout << "min = " << min << "\nmax = " << max << '\n';
23 }
What
The C++ code above reads integers from the standard input and keeps track of the largest and smallest values entered. After exhausting the input, it then prints those values. If the input contains no numbers, the program prints nothing. Let’s take a closer look at the various parts of the program.