Chapter 6 Exercise Set 1: Chapter Review¶
Write a program to test the
sequence
function introduced in the The while statement section. You should call this function frommain
with several different arguments, and observe its behavior.Write programs to test each of the following two functions:
void loop_forever(int n) { while (true) { cout << "n is now " << n << "." << endl; n = n + 1; } }
and
void recurse_forever(int n) { cout << "n is now " << n << "." << endl; recurse_forever(n + 1); }
Call these functions from your
main
function with1
as an argument. What happens?Do a web search for the term call stack (or runtime stack). What do you think the call stack has to do with the outcome of your experiment with these two functions?
Log tables may not be useful any more, but for computer scientists, knowing the powers of two is! Modify the last program in the Tables so that it outputs the powers of two up to 66536 (that’s \(2^{16}\)). Print it out and memorize it.
Rename the parameter
high
in the functionprint_multiples
in More generalization section toupper
. Put both of these in a file namedprint_mult_tables.cpp
that has amain
function that calls them. Compile and test your program and confirm that it works as expected.