C++ Quiz 4

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Tcarteronw
T
Tcarteronw
Community Contributor
Quizzes Created: 37 | Total Attempts: 31,078
Questions: 17 | Attempts: 708

SettingsSettingsSettings
C++ Quiz 4 - Quiz


Questions and Answers
  • 1. 

    What is the output of the following program fragment? cout << static_cast<double>(3)/4 << endl;

    • A.

      3

    • B.

      0.5

    • C.

      0

    • D.

      0.75

    Correct Answer
    D. 0.75
    Explanation
    The program fragment is using static_cast to convert the integer value 3 to a double before dividing it by 4. Since both 3 and 4 are integers, the division will be performed as integer division, resulting in the quotient 0. However, since the numerator is now a double, the result of the division will be implicitly converted to a double, resulting in the output of 0.75.

    Rate this question:

  • 2. 

    When parameters are passed between the calling code and the called function, parameters and arguments are matched by:

    • A.

      Their data types

    • B.

      Their relative positions in the parameter and argument lists

    • C.

      Their names

    • D.

      They are not matched up at all.

    Correct Answer
    B. Their relative positions in the parameter and argument lists
    Explanation
    When parameters are passed between the calling code and the called function, the matching of parameters and arguments is based on their relative positions in the parameter and argument lists. This means that the first parameter in the function's parameter list will be matched with the first argument in the calling code's argument list, the second parameter will be matched with the second argument, and so on. The matching is done based on the order in which the parameters and arguments are defined, regardless of their names or data types.

    Rate this question:

  • 3. 

    If you have the two functions as shown,      int someFunction(int value);      float someFunction(float value); and a variable x, which is a double, which function is called by the following statement?      cout << someFunction(x);

    • A.

      Void someFunction(int value);

    • B.

      Void someFunction(float value);

    • C.

      Nothing, it is a syntax error

    • D.

      Both functions are called

    Correct Answer
    C. Nothing, it is a syntax error
    Explanation
    The statement cout

    Rate this question:

  • 4. 

    Which of the following are valid function calls to the fabs function?

    • A.

      Fabs(3.5);

    • B.

      Cout

    • C.

      Cin >> fabs(3.5);

    • D.

      Fabs(cin >> x);

    • E.

      Fabs(3.5); and cout > fabs(3.5);

    • F.

      Fabs(3.5); and cout

    Correct Answer
    F. Fabs(3.5); and cout
    Explanation
    The function call fabs(3.5) is valid because it calls the fabs function with the argument 3.5, which returns the absolute value of 3.5. The function call cout is also valid because it is used to output data to the console. However, the other function calls are not valid. The function call cin >> fabs(3.5) is invalid because the cin function is used for input, not for calling a function. The function call fabs(cin >> x) is also invalid because it tries to use the cin function as an argument for the fabs function, which is not allowed. The function call cout > fabs(3.5) is invalid because the > operator is used instead of the

    Rate this question:

  • 5. 

    The functions pow(), sqrt(), and fabs() are found in which include file?

    • A.

      Cstdlib

    • B.

      Cmath

    • C.

      Iostream

    • D.

      Regular

    Correct Answer
    B. Cmath
    Explanation
    The functions pow(), sqrt(), and fabs() are found in the cmath include file.

    Rate this question:

  • 6. 

    The expression static_cast<double>(3) is called a

    • A.

      Type cast

    • B.

      Multiplier

    • C.

      Doubler

    • D.

      Polymorphism

    Correct Answer
    A. Type cast
    Explanation
    The expression static_cast(3) is called a type cast because it is used to explicitly convert the value 3 to the type double. Type casting allows for the conversion of one data type to another, and in this case, the integer value 3 is being converted to a double value. This is done by using the static_cast operator followed by the desired data type in angle brackets.

    Rate this question:

  • 7. 

    If the variable x has the original value of 3.4, what is the value in x after the following? cout << static_cast<int>(x);

    • A.

      3.4

    • B.

      4

    • C.

      Unknown

    • D.

      3

    Correct Answer
    D. 3
    Explanation
    The static_cast(x) statement converts the value of x to an integer. Since x has the original value of 3.4, it will be converted to the nearest integer, which is 3. Therefore, the value in x after the statement is 3.

    Rate this question:

  • 8. 

    What is the value of the following? sqrt(sqrt(pow(2,4)));

    • A.

      1

    • B.

      2

    • C.

      4

    • D.

      16

    Correct Answer
    B. 2
    Explanation
    The given expression calculates the square root of the square root of 2 raised to the power of 4. First, 2 raised to the power of 4 is calculated, which equals 16. Then, the square root of 16 is taken, resulting in 4. Finally, the square root of 4 is calculated, which equals 2. Therefore, the value of the expression is 2.

    Rate this question:

  • 9. 

    Using functions in a program is known as

    • A.

      Data abstraction

    • B.

      Procedural abstraction

    • C.

      Poor programming style

    • D.

      Calculus

    Correct Answer
    B. Procedural abstraction
    Explanation
    Procedural abstraction refers to the practice of using functions in a program. Functions allow us to break down complex tasks into smaller, more manageable parts, making the code easier to understand and maintain. By encapsulating a set of instructions within a function, we can reuse that code whenever needed, improving code reusability and reducing redundancy. Therefore, the correct answer is procedural abstraction.

    Rate this question:

  • 10. 

    Which of the following are valid function calls to the pow function?

    • A.

      Pow(int x, int y);

    • B.

      Pow(2);

    • C.

      Pow(1.1,3.0);

    • D.

      Double pow(1.1,3.0);

    Correct Answer
    C. Pow(1.1,3.0);
    Explanation
    The only valid function call to the pow function is pow(1.1,3.0). This is because the pow function takes two arguments, both of which must be of type int or double. The first function call pow(int x, int y) is invalid because it does not provide the required second argument. The second function call pow(2) is also invalid because it does not provide the required first argument. The fourth function call double pow(1.1,3.0) is invalid because it includes the data type "double" before the function name, which is not allowed.

    Rate this question:

  • 11. 

    If you have the following variable declaration in your program, const int SIZE=34; then which of the following statements are legal?

    • A.

      SIZE ++;

    • B.

      X = SIZE--;

    • C.

      Cout

    • D.

      Cin >> SIZE;

    Correct Answer
    C. Cout
    Explanation
    The statement "cout" is legal because it is used to display the value of the variable SIZE.

    Rate this question:

  • 12. 

    Which of the following functions is a properly overloaded function of the following? int doSomething(int first, float second);

    • A.

      Float doSomething(int first, float second);

    • B.

      Int doSomething( int next, float last);

    • C.

      Int doSomething(int first, int second, float third);

    • D.

      Int doSome(int first, float second);

    Correct Answer
    C. Int doSomething(int first, int second, float third);
    Explanation
    The correct answer is "int doSomething(int first, int second, float third)" because it has the same function name "doSomething" and the same parameter types "int, int, float" as the original function. Overloading a function means creating a new function with the same name but different parameters.

    Rate this question:

  • 13. 

    Which of the following are not legal function declarations?

    • A.

      Int ave3(int a, int b, int c);

    • B.

      Int 3ave(int a, int b, int c);

    • C.

      Int ave3(int, int, int);

    • D.

      Int ave_3(int a1, int a2, int a3);

    Correct Answer
    B. Int 3ave(int a, int b, int c);
    Explanation
    The function declaration "int 3ave(int a, int b, int c);" is not legal because function names cannot start with a number.

    Rate this question:

  • 14. 

    Information Hiding is analogous to using

    • A.

      An algorithmic design

    • B.

      A black-box methodology

    • C.

      Formal parameters

    • D.

      Actual parameters

    Correct Answer
    B. A black-box methodology
    Explanation
    Information hiding is a concept in software engineering that suggests hiding the implementation details of a module or component from other parts of the system. This is similar to using a black-box methodology, where the internal workings of the system are hidden and only the inputs and outputs are visible. By using a black-box methodology, the details of how the system functions are abstracted away, allowing for easier understanding and maintenance of the system as a whole. Similarly, information hiding allows for better modularization and encapsulation of code, making it easier to modify and maintain.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jun 02, 2013
    Quiz Created by
    Tcarteronw
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.