QUESTION 1
What does the following code segment output?
int red, blue;
red = 7;
blue = red + 2 * 5
red++;
blue = blue + red;
cout << blue;
4 points
QUESTION 2
Is the following statement true or false?
The Boolean expression in the following if statement will be true for all values of x in the range from 10 to 20 (including the endpoints) and false for all other values:
int x;
if (x >= 10 && x <= 20)
True
False
4 points
QUESTION 3
Give the appropriate order of steps when a C++ function call is made:
- 1. 2. 3. 4.Function return value is returned
Function code runs
Call by reference parameter values are returned
Parameter passing
4 points
QUESTION 4
Which of the following C++ statement sequences has legal syntax?
1. |
double this; int that; cin >> this >> that; |
|
2. |
int x, y; cin << x << y; |
|
3. |
int x, y; cin << "x = " << x << " y = " << y; |
|
4. |
int one, two; cin >> one, two; |
4 points
QUESTION 5
What is the output from the following C++ code:
if (7 > 3)
cout << "Hello";
cout << "Goodbye":
HelloGoodbye |
||
[Nothing will be printed] |
||
Hello |
||
Goodbye |
4 points
QUESTION 6
What does the following output?
int x = 2;
char letter = 'w';
cout << letter << "x" << x;
4 points
QUESTION 7
What is the value of the following expression:
42 % 6
4 points
QUESTION 8
Select all of the following which are legal variable names in C++.
HELLOTHERE |
||
Hello There |
||
Hello+There |
||
HelloThere |
||
Hello_There |
||
Hello-There |
6 points
QUESTION 9
How many times will the following code print Hello?
int x = 2;
do
{
x = x + 4;
cout << "Hello";
}
while (x < 9);
4 points
QUESTION 10
Match the following variable descriptions to the appropriate C++ type.
|
|
4 points
QUESTION 11
Given the following control associated with a for statement, how many times will the loop code execute?
int x;
for (x = 2; x < 6; x++)
4 points
QUESTION 12
Consider the following function call (assume that the call is correct):
answer = myFun (x, y, z);
Indicate whether the following statement is true or false:
Parameters x, y, and z will be passed by position to the three parameters in the function definition of myFun.
True
False
4 points
QUESTION 13
Consider the following function call (assume that the call is correct):
answer = myFun (x, y, z);
Indicate whether the following statement is true or false:
The return value from myFun will be assigned to answer.
True
False
4 points
QUESTION 14
Match the statement type to the description.
|
|
5 points
QUESTION 15
Show the output for the following code. Use a '$' character to represent each space. Assume all other code is correct and the iomanip library has been included.
double x = 7.6;
cout << showpoint << fixed << setprecision (3);
cout << setw (6) << x;
4 points
QUESTION 16
What will be the value of x after the following code executes:
int x;
x = 3;
x += 7;
x = x - 2;
4 points
QUESTION 17
Is the following statement true or false?
When we have the following start of a switch statement:
switch (var)
it is legal C++ for var to be of type int.
True
False
4 points
QUESTION 18
Here is a C++ function protoype:
int runOut (double x, int& y);
Which of the following could possibly be a legal call to the function runOut?
z = runOut (x, y, z); |
||
runOut (x, &y); |
||
cow = runOut (y, x); |
||
y = runOut (x); |
4 points
QUESTION 19
Is the following statement true or false?
The Boolean expression in the following if statement will be true for all integer values of x in the range from 1 to 3 (including the endpoints) and false for all other values:
int x;
if (x == 1 || 2 || 3)
True
False
4 points
QUESTION 20
What is the output for the following code:
if (!(7 < 10))
cout << "blue";
else
{
cout << "red";
cout << "green";
}
red |
||
blue |
||
redgreen |
||
green |
4 points
QUESTION 21
What value should a running sum variable be initialized to?
4 points
QUESTION 22
What will be printed by the following code segment:
int x = 5;
while (x < 30)
{
x = x + 9;
}
cout << x;
4 points
QUESTION 23
Is the following statement true or false?
C++ is case sensitive in regards to variable names.
True
False
2 points
QUESTION 24
What is the typical ordering of the following function parts in a C++ program?
- 1. 2. 3.call
prototype
definition
3 points
QUESTION 25
What will be the value of x after the following statements execute:
int x;
x = 2 * 3 - 15 / 5 + 2 * 4;
int red, blue; // Two variable named red and blue is declared
red = 7; // 7 is assigned to red variable
blue = red + 2 *5; // * has higher presedence than +, so blue = 7 + (2 * 5) = 17
red ++ ; // Value of red is incremented by 1, so now red contains 8.
blue = blue + red; // Previously blue = 17, red = 8, Now blue = 17 + 8 = 25
cout<<blue; // This will print the value of blue variable which is 25. So answer is 25.
2. Answer: True
if (x > = 10 && x<=20) // This means x can take any integer value between 10 and 20 and including 10 and 20. So if statement is true for all values of x in range from 10 to 20, including 10 and 20.
Get Answers For Free
Most questions answered within 1 hours.