Emma is writing her first C++ program. She wants to use the cout and cin objects without qualifying them with std::. Which directive should she include at the beginning of her program?

  • #include
  • #include
  • #include
  • #include
Emma should include the directive #include at the beginning of her program to access the cout and cin objects without qualifying them with std::. This directive provides access to the standard I/O stream objects.

When would you use a do-while loop over a while loop?

  • When you want to create an infinite loop.
  • When you want to execute the loop body a fixed number of times.
  • When you want to execute the loop body at least once.
  • When you want to loop through a collection.
You would use a do-while loop over a while loop when you want to ensure that the loop body is executed at least once, regardless of whether the initial condition is true or false. The condition is checked after the first execution in a do-while loop.

If a function is declared but not defined in a program, what will be the outcome during the linking phase?

  • Compilation error
  • Linker error
  • No error, it will use a default implementation
  • Runtime error
If a function is declared but not defined in a program, it will result in a linker error during the linking phase. This error occurs because the linker cannot find the actual implementation of the function, and therefore, it cannot resolve references to that function.

Samantha encounters a scenario where she needs to exit out of multiple nested loops upon a particular condition. What programming construct can she use to achieve this efficiently?

  • break
  • continue
  • goto
  • return
Samantha can use the break statement to efficiently exit out of multiple nested loops upon a particular condition. When the break statement is encountered, it terminates the innermost loop and continues executing the code after the loop. It's important to use this construct judiciously to avoid unexpected behavior.

The ______ keyword is used to define a condition in C++.

  • case
  • else
  • if
  • switch
In C++, the "if" keyword is used to define a condition. It's a fundamental control structure for conditional execution in the language. You use "if" to specify a condition that, if true, executes a block of code.

Emily is writing a function to calculate the factorial of a number using a loop. Which loop structure would be the most appropriate for this task?

  • Do-While Loop
  • For Loop
  • Switch Statement
  • While Loop
Emily should use a For Loop to calculate the factorial of a number. A For Loop is well-suited for tasks where you know in advance how many iterations are required, as is the case with factorial calculations. She can initialize the loop variable, set the loop condition to run until the variable reaches 1, and decrement the variable in each iteration to multiply the numbers in a descending order.

Jake wants to add 5 and 7, and then multiply the result by 3. Which of the following expressions will give the correct result?

  • (5 + 7) * 3
  • 5 * 7 + 3
  • 5 + (7 * 3)
  • 5 + 7 * 3
To get the correct result, Jake should add 5 and 7 first and then multiply the result by 3. The expression (5 + 7) * 3 achieves this, providing the correct answer of 36.

The mechanism of selecting the most appropriate method for a particular call from the set of overloaded methods is called ______.

  • Function Overriding
  • Function Resolution
  • Method Overloading
  • Method Resolution
The process of selecting the most appropriate method from a set of overloaded methods is called 'Method Resolution' or 'Function Resolution.' This is determined by the number and types of arguments in the function call. It's a crucial concept in polymorphism and method overloading in C++.

Which loop in C++ tests the condition before executing its body?

  • do-while loop
  • for loop
  • switch loop
  • while loop
The while loop in C++ tests the condition before executing its body. It's a pre-test loop, meaning that it evaluates the condition first, and if it's true, it enters the loop body. This loop is suitable when you want to execute a block of code as long as a condition is true initially.

What keyword is used before a function to make it an inline function?

  • function
  • inline
  • public
  • void
The inline keyword is used before a function in C++ to make it an inline function. An inline function is a request to the compiler to insert the code of the function at the calling point instead of performing a normal function call. This can improve performance in certain situations by reducing the overhead of function calls.