Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 1 If this code fragment were executed in an otherwise correct and compl

ID: 3854115 • Letter: Q

Question

Question 1

If this code fragment were executed in an otherwise correct and complete program, what would the output be?

int a = 3, b = 2, c = 5
if (a > b)
a = 4;
if ( b > c)
   a = 5;
   else
    a = 6;
cout << a << endl;

5

4

3

6

Question 2

Which statement results in the value false?

The value of count is 0; limit is 10.

(count == 0)&&(limit < 20)

(count != 0)&&(limit < 20)

(count == 0)&&(limit < 20)

(count != 0)||(limit < 20)

Question 3

Which of the following overloadings will be invoked by this call?

g(1,2);

void g(double value, int count);

None listed

int g(int count, double value);

void g(int value, int count);

Question 4

A call to a C++ function is

The name of the function followed by exactly the number of arguments as there are parameters in the definition

The name of the function followed by empty parentheses

The name of the function followed by any number of arguments, regardless of the number of parameters in the definition

The name of the function only

Question 5

Which is incorrect regarding

a void function

performs some action and returns a value

performs some action but does not return a value

is a statement

A void function may have a return statement but is not required to have one.

Question 6

Which is incorrect?

The sqrt function

is provided in the <cmath> library header

the argument type is int

returns the square root of the argument

the return type is double

Question 7

Which statement results in the value false?

The value of count is 0; limit is 10.

(count != 0)&&(limit < 20)

(count == 0)&&(limit < 20)

(count != 0)||(limit < 20)

(count == 0)&&(limit < 20)

Question 8

The following program purports to sum all entered int values that are greater than 5. It compiles without any error message, and it executes without error message, but nevertheless is wrong. Which statement is incorrect?

// Display the sum of all entered int values
// greater than 5
#include <iostream>

int main()
{
using namespace std;
int x, sum;
while (x < 10)
{
     cin >> x;
     if (x > 5);
       sum = sum +x;
}
cout << “The sum is values > 5 is “ << sum << endl;
}

A) The semicolon at the end of the if statement is an error that the compiler should catch

B) The variable x is not initialized, so the loop may or may not execute

C) The semicolon at the end of the if statement causes all entered values to be summed

D) The sum variable is not initialized, so the output value is most likely garbage

Question 9

A switch statement must have

None listed

a default case

a break statement

more than one non-default case

Question 10

What is incorrect about the expression below?

left && right

The expression is true when left is true and right is false

The expression is false when left is false and right is true

The expression is true when left is true and right is true

The expression is false when left is false and right is false

Question 11

Which is correct?

When a loop is nested in side another loop, a break or continue statement terminates or restarts the outermost loop of the nested loop structure.

A break statement is used in loops only.

In a while loop, the Boolean_Expression is executed before each execution of the loop body.

In a do-while loop, a continue statement terminates the loop

Question 12

Which of the following determines the operator that is processed prior to another operator?

None listed

Operator associativity

Whether the operator is an arithmetic operator

Operator precedence

Question 13

Which of the following control structures requires curly braces?

while

switch

for

if-else

Question 14

In distinguishing an expression as true or false, C++ sees which of the following as true?

Any non-zero value

1

0

true

Question 15

Which of the following loop statements is guaranteed to iterate the body of the loop at least once?

all listed

while(control) {body};

for(initialize;test:update){body};

do {body} while(control)

Question 16

In the expression (j > 0 && j+1 == 10), which operator executes last?

>

+

&&

==

Question 17

If this code fragment were executed in an otherwise correct and complete program, what would the output be? .

int a = 3, b = 2, c = 5

if (a > b)

a = 4;

if ( b > c)

a = 5;

else

a = 6;

cout << a < endl;

4

3

5

6

Question 18

Which control construct repeats a sequence of statements zero or more times?

while statement

if-else statement

switch

do -while statement

Question 19

In a switch statement, when a break statement is encountered, an immediate transfer of control is made to

A) the default case of the switch statement

B) a goto statement

C) the else statement

D) the statement beyond the end of the switch statement

Question 20

Which of the following is NOT correct about the || operator?

It can have two operands

It is the logical OR operator

It returns true if both operands are true

It uses short circuit evaluation

A)

5

B)

4

C)

3

D)

6

Explanation / Answer

Question 1: D) 6
Question 2: B) (count != 0)&&(limit < 20)
Question 3: D) void g(int value, int count);
Question 4: A) The name of the function followed by exactly the number of arguments as there are parameters in the definition
Question 5: B) performs some action but does not return a value
Question 6: B) the argument type is int
Question 7: A) (count != 0)&&(limit < 20)
Question 8: D) The sum variable is not initialized, so the output value is most likely garbage
Question 9: C) a break statement
Question 10: B) The expression is false when left is false and right is true
Question 11: B) A break statement is used in loops only.
Question 12: D) Operator precedence
Question 13: B) switch
Question 14: B) 1 D) true
Question 15: D) do {body} while(control)
Question 16: C) &&
Question 17: D) 6
Question 18: D) do -while statement
Question 19: D) the statement beyond the end of the switch statement
Question 20: D) It uses short circuit evaluation

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote