NEW
Font size
WorksheetsChapter 3 C++
Total questions: 7
Worksheet time: 4mins
The area of a circle is calculated by multiplying PI by radius squared, or simply:
PI * radius * radius
In the above expression, radius can be r, or x, or rad, or whatever you want it to be. Assume the variable is named radius, for readability. Take a look at the following if statement. The area of the circle is calculated and displayed to the console ONLY IF what?
if (radius >= 0)
cout << radius * radius * 3.14159;
The value in the radius variable is either greater than 0 or equal to 0
The value in the radius variable is greater than 0
The value in the radius variable is equal to 0
The value in the radius is a negative value
Analyze the following code.
bool even = false;
if (even)
{
cout << "It is even!";
}
Nothing is displayed.
It is even! is displayed
false is displayed
Rewrite the following if-else statement using a conditional (aka. ternary operator):
if (x > 10)
score = 3 * scale;
else
score = 4 * scale;
score = (x > 10) ? 3 : 4 ;
score = (x > 10) ? 3 * scale : 4 * scale;
(x > 10) ? 3 * scale : 4 * scale;
cout << (x > 10) ? 3 * scale : 4 * scale;
The following code displays ___________.
double temperature = 50;
if (temperature >= 100)
cout << "too hot" << endl;
else if (temperature <= 40)
cout << "too cold" << endl;
else
cout << "just right" << endl;
too cold
too hot
just right
nothing is displayed
You can always convert an if statement to a switch statement.
True
False
Including a space between the relational operators >=, <=, ==, and != causes a syntax error. For example:
>= is not the same as > =
<= is not the same as < =
== is not the same as = =
True
False
Suppose cond1 and cond2 are two Boolean expressions. When will the following if condition be true?
if (cond1 && cond2)
When either cond1 or cond2 are true
When both cond1 and cond2 are true
When cond1 is false and cond2 is false
