Question: The default case is required in the switch selection statement
False
Question: The break statement is required in the default case of a switch selection
statement to exit the switch properly
False
Question: The expression (x > y && a < b) is true if either the expression x > y is true
or the expression a < b is true
False
Question: An expression containing the || operator is true if either or both of its operands
are true
True
Question: Write a C++ statement or a set of C++ statements to sum the odd integers
between 1 and 99 using a for statement. Assume the integer variables sum and count have
been declared
sum = 0;
for (count = 1; count <= 99; count += 2) sum += count;
Question: Write a C++ statement or a set of C++ statements to print the value
333.546372 in a field width of 15 characters with precisions of 1, 2 and 3. Print each
number on the same line. Left-justify each number in its field.
cout << fixed << left
<< setprecision(1) << setw(15) << 333.546372
<< setprecision(2) << setw(15) << 333.546372
<< setprecision(3) << setw(15) << 333.546372
<< endl;
Question: Write a C++ statement or a set of C++ statements to calculate the value of 2.5
raised to the power 3 using function pow. Print the result with a precision of 2 in a field
width of 10 positions
cout << fixed << setprecision(2) << setw(10) << pow(2.5, 3) << endl;
Question: Write a C++ statement or a set of C++ statements to print the integers from 1
to 20 using a while loop and the counter variable x. Assume that the variable x has been
declared, but not initialized. Print only 5 integers per line. [Hint: Use the calculation x %
|
|
5. When the value of this is 0, print a newline character; otherwise, print a tab character.]
x = 1;
while (x <= 20)
{
cout << x;
if (x % 5 == 0)
cout << endl;
Else
cout << '\t';
x++;
}
Question: Find the error(s) in the following code segment:
x = 1;
while (x <= 10);
x++;
}x = 1;
while (x <= 10)
x++;
}
Question: Find the error(s) in the following code segment:
for (y =.1; y!= 1.0; y +=.1) cout << y << endl;
for (y = 1; y!= 10; y++) cout << (static_cast< double >(y) / 10
) << endl;
Question: Find the error(s) in the following code segment:
switch (n)
{
case 1:
cout << "The number is 1" << endl;
case 2:
cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Switch (n)
{
case 1:
cout << "The number is 1" << endl;
break;
case 2: cout << "The number is 2" << endl;
break;
default:
cout << "The number is not 1 or 2" << endl;
break;
}
Question: Find the error(s) in the following code segment. The following code should
print the values 1 to 10:
n = 1;
while (n < 10) cout << n++ << endl;
n = 1;
while (n < 11) cout << n++ << endl;
Question: What variable is?