- Write a clearly legible T to the left of each of the
following statements that is true and a
clearly legible F to the left of each that is false.
- A function contract usually cannot be written until after the
function is written.
- A function typically is given its data through its parameters.
- In order for a function to get any data to work on, it must
include a "cin" line.
- The data type of real numbers is called real in C++.
- C++ uses 0 to mean "false" and 1 to mean "true".
- C++ is a professional software development language.
- The word if in C++ is usually used to start a loop.
- Function f2 is shown below,
with part of its definition not shown, and replaced by three
dots. There are no breaks in the part that is not shown, and
nothing is printed there. (You have not seen breaks yet.)
It is known that f2 prints something when it runs. What does it print?
- 24
- 25
- 26
- It is impossible to say without more information.
void f2()
{
int i = 100;
while(i != 25) {
...
i = i + 1;
}
cout << i;
}
- The following loop sets variable m to
- 1 + ... + 9
- 1 + ... + 10
- 1 + ... + 11
- 1 + ... + 12
int m,n;
n = 0;
m = 0;
while(n < 10) {
n++;
m = m + n;
}
- The following sets variable x to
- 2
- 3
- 4
- 5
int x,y,z;
y = 4;
z = y - 1;
if(y > z || z < 0) x = z - 1;
else x = z + 1;
- What is printed by the following C++ function when it is run?
Be careful to note that
all of the variables hold integers.
void four()
{
int x,y,z,w,b;
x = 45;
y = 2 * x + x * 3;
z = x / 2;
w = x % 2;
b = x < y;
cout << "x = " << x << " y = " << y << " z = " << z
<< " w = " << w << " b = " << b << endl;
}
Answer: ________________________________________________________
- The geometric mean of two numbers x and y is the square root of
the product of x and y.
Write a C++ function called geometricMean that returns the
geometric mean of its two parameters.
double geometricMean(double x, double y)
- Using function geometricMean from the previous exercise,
write a program fragment
that sets variable z to the geometric mean of variable r and
twice variable s.
- Function f is defined as follows.
int f(int x)
{
int k = 1;
while(k <= x) {
k = k + k;
}
return k;
}
What are f(3) and f(f(3))?
f(3) = _________
f(f(3)) = _________