C++ Mid Term

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: 38 | Total Attempts: 30,632
Questions: 47 | Attempts: 421

SettingsSettingsSettings
C++ Mid Term - Quiz


Questions and Answers
  • 1. 

    If a function needs to modify more than one variable, it must

    • A.

      Be pass by value

    • B.

      Be a void function

    • C.

      Return all values needed

    • D.

      Be a call by reference function

    Correct Answer
    D. Be a call by reference function
    Explanation
    If a function needs to modify more than one variable, it must be a call by reference function. This is because call by reference allows the function to directly access and modify the original variables passed to it, rather than creating copies of the variables. This ensures that any modifications made within the function are reflected in the original variables outside of the function. Pass by value creates copies of the variables, so any modifications made within the function do not affect the original variables. A void function does not necessarily modify variables, and returning all values needed may not be practical or efficient in some cases.

    Rate this question:

  • 2. 

    When a void function is called, it is known as

    • A.

      An output function.

    • B.

      A returned value.

    • C.

      An executable statement.

    • D.

      A comment

    Correct Answer
    C. An executable statement.
    Explanation
    When a void function is called, it is considered as an executable statement because it performs a specific task or action within the program. Unlike functions that return a value, void functions do not produce any output or returned value. Instead, they are designed to execute a set of instructions or operations without returning any result. Therefore, the correct answer is "An executable statement."

    Rate this question:

  • 3. 

    What is the output of the following code fragments? int trial( int& a, int b) {             if(b > a)             {                         a=b;                         return –a;             }             else             {                         return 0;             } }   float x=0, y=10,z; z=trial(y,x); cout << z << " " << x <<" " << y << endl;

    • A.

      –10 0 0

    • B.

      0 1 0 0

    • C.

      1 0 0 0

    • D.

      0 0 1 0

    Correct Answer
    D. 0 0 1 0
    Explanation
    The code defines a function called "trial" that takes two integer parameters, "a" and "b". Inside the function, it checks if "b" is greater than "a". If it is, it assigns the value of "b" to "a" and returns the negative value of "a". If "b" is not greater than "a", it simply returns 0.

    In the main code, it declares three float variables, "x", "y", and "z". "x" is initialized to 0, "y" is initialized to 10. Then, it calls the "trial" function with "y" and "x" as arguments and assigns the return value to "z". Finally, it prints the values of "z", "x", and "y".

    The output of the code will be "0 0 1 0" because the value of "z" will be 0, the value of "x" will remain 0, and the value of "y" will remain 10.

    Rate this question:

  • 4. 

    Which of the following comments would be the best post-condition for this swap function void swap( int& left, int&right);

    • A.

      //Postcondition: None

    • B.

      //Postcondition: the values of left and right are exchanged.

    • C.

      //Postcondition: left has the value of right

    • D.

      //Postcondition: left and right are unchanged

    Correct Answer
    B. //Postcondition: the values of left and right are exchanged.
    Explanation
    The best post-condition for the swap function void swap( int& left, int& right) would be "//Postcondition: the values of left and right are exchanged." This post-condition accurately describes the expected outcome of the swap function, which is to exchange the values of the variables left and right.

    Rate this question:

  • 5. 

    Call-by-reference should be used

    • A.

      For all variables

    • B.

      When the function needs to change the value of one or more arguments

    • C.

      Never

    • D.

      Only in void functions

    Correct Answer
    B. When the function needs to change the value of one or more arguments
    Explanation
    Call-by-reference should be used when the function needs to change the value of one or more arguments. This is because call-by-reference allows the function to directly access and modify the original variables, rather than creating copies of them. This is particularly useful when the function needs to make permanent changes to the variables that should be reflected outside of the function's scope.

    Rate this question:

  • 6. 

    A simplified main program used to test functions is called

    • A.

      A stub

    • B.

      Abstraction

    • C.

      Polymorphism

    • D.

      A driver

    Correct Answer
    A. A stub
    Explanation
    A stub is a simplified main program used to test functions. It is typically used when a function or module is not yet fully implemented or when the main program is not yet available. A stub provides a basic framework for testing the functionality of individual functions before integrating them into the main program.

    Rate this question:

  • 7. 

    When a variable is local to a function, we say that it has ___ of the function

    • A.

      Value

    • B.

      Constance

    • C.

      Scope

    • D.

      Locality

    Correct Answer
    C. Scope
    Explanation
    When a variable is local to a function, it means that it can only be accessed and used within that specific function. The scope of a variable refers to the portion of the code where the variable is visible and can be used. In this case, the variable's scope is limited to the function in which it is defined, and it cannot be accessed from outside of that function.

    Rate this question:

  • 8. 

    Testing your program should be done

    • A.

      As each function is developed

    • B.

      At the end of the coding

    • C.

      Only if there appear to be problems

    • D.

      Only if your instructor requires it.

    Correct Answer
    A. As each function is developed
    Explanation
    Testing your program should be done as each function is developed because it allows for early detection and resolution of any issues or bugs that may arise during the development process. By testing each function individually, it ensures that they are working correctly before moving on to the next function. This approach helps in identifying and fixing any errors early on, leading to a more efficient and effective development process.

    Rate this question:

  • 9. 

    If you write a function that should use call-by-reference, but forget to include the ampersand,

    • A.

      The program will not compile

    • B.

      The program will not link

    • C.

      The program will not run without a run-time error

    • D.

      The program will run but probably not give you the correct information.

    Correct Answer
    D. The program will run but probably not give you the correct information.
    Explanation
    When a function is supposed to use call-by-reference, it means that the function should be able to modify the values of the variables passed to it. However, if the ampersand (&) is forgotten while passing the variables to the function, the function will not be able to access the original variables and modify their values. As a result, the program will still run, but the function will not give the correct information because it is not actually modifying the original variables.

    Rate this question:

  • 10. 

    What is wrong with the following code? int f1( int x, int y) {             x = y * y;             return x;             int f2( float a, float& b) {             if(a < b)                         b = a;             else                         a=b;             return 0.0;        } }

    • A.

      Neither function should return a value

    • B.

      Function definitions may not be nested

    • C.

      Both parameters to f2 should be pass-by reference

    • D.

      In f2, a can not be assigned b.

    • E.

      Nothing is wrong

    Correct Answer
    B. Function definitions may not be nested
    Explanation
    The code provided contains two function definitions, f1 and f2, which are nested within each other. However, in C++, function definitions cannot be nested. Each function should be defined separately and outside of any other function. Therefore, the correct answer is that function definitions may not be nested.

    Rate this question:

  • 11. 

    In the following function, what is passed to the first parameter? void f1( int& value1, int value2);   int x,y; f1(x,y);

    • A.

      The value of x

    • B.

      Nothing, it is a void function

    • C.

      The value of y

    • D.

      The variable x (or its memory location)

    Correct Answer
    D. The variable x (or its memory location)
    Explanation
    In the given code, the function f1 is called with two arguments, x and y. The first parameter of the function is passed by reference, indicated by the use of the ampersand (&) symbol. This means that the function will receive the memory location of the variable x, rather than its value. Therefore, the correct answer is that the variable x (or its memory location) is passed to the first parameter of the function.

    Rate this question:

  • 12. 

    the fabs(double num) function

    • A.

      Returns the most fabulous number

    • B.

      Returns the largest whole number

    • C.

      Returns the negative value of num

    • D.

      Returns the absolute value of num

    Correct Answer
    D. Returns the absolute value of num
    Explanation
    The fabs(double num) function is used to calculate the absolute value of a given number. It returns the positive value of num, regardless of its original sign.

    Rate this question:

  • 13. 

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

    • A.

      3

    • B.

      0.5

    • C.

      0

    • D.

      0.75

    Correct Answer
    C. 0
    Explanation
    The program fragment is using static_cast to convert the result of the division operation 3/4 to an integer. Since both 3 and 4 are integers, the division operation will result in an integer division. In integer division, the fractional part is truncated, so the result of 3/4 is 0. Therefore, the output of the program fragment will be 0.

    Rate this question:

  • 14. 

    If you need to write a function that will compute the cost of some candy, where each piece costs 25 cents, which would be an appropriate function declaration?

    • A.

      Int calculateCost(char name);

    • B.

      Char calculateCost(int count);

    • C.

      Int calculateCost int count;

    • D.

      Int calculateCost(int count);

    Correct Answer
    D. Int calculateCost(int count);
    Explanation
    The appropriate function declaration would be "int calculateCost(int count)" because it specifies the return type as an integer and takes an integer parameter "count". This matches the requirement of computing the cost of candy based on the number of pieces, where each piece costs 25 cents.

    Rate this question:

  • 15. 

    What is the value returned by the following function? int function() {       int value = 35;       return value + 5;       value += 10; }

    • A.

      35

    • B.

      40

    • C.

      50

    • D.

      10

    Correct Answer
    B. 40
    Explanation
    The function returns the value of "value" variable incremented by 5, which is 40. The line "value += 10;" is never executed because it comes after the return statement, so it does not affect the returned value.

    Rate this question:

  • 16. 

    When overloading a function, what must be true?

    • A.

      The names should be different with the same number and/or types of parameters.

    • B.

      The names should be the same with different number and/or types of parameters.

    • C.

      The names should be different with different number and/or types of parameters.

    • D.

      The names should be the same with the same number and/or types of parameters.

    Correct Answer
    B. The names should be the same with different number and/or types of parameters.
    Explanation
    When overloading a function, the names should be the same, but the number and/or types of parameters should be different. This allows the compiler to distinguish between different versions of the function based on the arguments passed to it.

    Rate this question:

  • 17. 

    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, they are matched by 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 passed in the function call, the second parameter will be matched with the second argument, and so on. The matching is based on the order in which the parameters and arguments are listed, ensuring that the correct values are assigned to the corresponding parameters in the function.

    Rate this question:

  • 18. 

    The expression static_cast<int>(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 convert the value 3 from its original type (which is likely a floating-point or enumeration type) to the integer type. The static_cast keyword is used in C++ to perform explicit type conversions. By using static_cast(3), we are explicitly telling the compiler to treat the value 3 as an integer.

    Rate this question:

  • 19. 

    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.

      3

    • D.

      Unknown

    Correct Answer
    C. 3
    Explanation
    The code snippet is using the static_cast function to convert the variable x from a float to an integer. This function truncates the decimal part of the number and returns the integer value. Therefore, the value of x after the code is executed will be 3.

    Rate this question:

  • 20. 

    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 evaluates 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, resulting in 16. Then, the square root of 16 is taken, resulting in 4. Finally, the square root of 4 is calculated, resulting in 2. Therefore, the value of the given expression is 2.

    Rate this question:

  • 21. 

    What is the value of i after the following function call? //function definition int doSomething(int value) {             value = 35;             return value;             value = 13 }   //fragment of main program int i=0; cout << doSomething(i);

    • A.

      13

    • B.

      35

    • C.

      48

    • D.

      0

    Correct Answer
    D. 0
    Explanation
    The value of i after the function call is 0 because the function doSomething assigns the value of 35 to the parameter value, but then it immediately returns that value without assigning it to any variable. Therefore, the original value of i, which is 0, remains unchanged.

    Rate this question:

  • 22. 

    What is the output of the following code fragement?   double size, volume=16.0; size = sqrt(sqrt(volume)) / 3; cout << fixed << showpoint <precision(2);

    • A.

      0.67

    • B.

      0.6666667

    • C.

      0.00

    • D.

      0

    Correct Answer
    A. 0.67
    Explanation
    The code fragment calculates the size of an object based on its volume. It uses the sqrt() function to find the square root of the volume, and then divides it by 3. The output statement uses the fixed, showpoint, and precision(2) manipulators to format the output with 2 decimal places. Therefore, the output will be 0.67.

    Rate this question:

  • 23. 

    Information Hiding is analogous to using

    • A.

      An algorithmic design

    • B.

      A black-box methodology

    • C.

      Actual parameters

    Correct Answer
    B. A black-box methodology
    Explanation
    Information hiding is analogous to using a black-box methodology because both involve hiding the internal details of a system or process. In information hiding, the internal implementation details of a module or class are hidden, and only the necessary information is exposed to the outside world. Similarly, in a black-box methodology, the internal workings of a system or process are hidden, and only the inputs and outputs are visible. Both approaches prioritize encapsulation and abstraction, allowing for easier understanding, maintenance, and modification of the system or process.

    Rate this question:

  • 24. 

    What is the output of the following function call? //function body int factorial(int n) {       int product=0;       while(n > 0)       {                   product = product * n;                   n—;       }       return product; }   //function call cout << factorial(4);

    • A.

      4

    • B.

      0

    • C.

      24

    • D.

      48

    Correct Answer
    B. 0
    Explanation
    The output of the function call is 0. This is because the variable "product" is initially assigned a value of 0 and is never updated within the while loop. Therefore, the final value of "product" remains 0 and is returned as the output.

    Rate this question:

  • 25. 

    Which of the following are equivalent to (!(x<15 && y>=3))?

    • A.

      (x>15 && y

    • B.

      (x>=15 && y < 3)

    • C.

      (x>=15 || y < 3)

    • D.

      (x>15 || y < 3)

    Correct Answer
    C. (x>=15 || y < 3)
    Explanation
    The given expression is a negation of the original expression. The original expression is "x=3". Negating this expression gives us "!(x=3)". By De Morgan's law, this can be simplified to "(x>=15 || y=15 || y

    Rate this question:

  • 26. 

    Given the following code, what is the final value of i?       int i,j;       for(i=0;i<4;i++)       {                   for(j=0;j<3;j++)                   {                               if(i==2)                                           break;                   }       }

    • A.

      3

    • B.

      4

    • C.

      5

    • D.

      0

    Correct Answer
    B. 4
    Explanation
    The final value of i is 4 because the outer loop will iterate 4 times (i=0,1,2,3). However, when i=2, the inner loop will break, causing the outer loop to skip the remaining iterations and move on to the next value of i. Therefore, the inner loop will only run twice (j=0,1) for i=2, and the final value of i will be 4.

    Rate this question:

  • 27. 

    Which of the following data types may be used in a switch statement?

    • A.

      Int

    • B.

      Char

    • C.

      Enum

    • D.

      Long

    • E.

      All are correct

    Correct Answer
    E. All are correct
    Explanation
    In a switch statement, any of the given data types (int, char, enum, long) may be used. The switch statement allows for multiple cases to be evaluated based on the value of a variable, and it can handle different data types as long as they are compatible with the switch expression. Therefore, all of the given data types are correct options for a switch statement.

    Rate this question:

  • 28. 

    What is wrong with the following for loop?       for(int i=0;i<10;i--)       {                   cout << "Hello\n";       }

    • A.

      Can not use a for-loop for this

    • B.

      I is not initialized

    • C.

      Infinite loop

    • D.

      Off-by-one error

    Correct Answer
    C. Infinite loop
    Explanation
    The given for loop will result in an infinite loop because the condition `i--` will always evaluate to true. The loop starts with `i` initialized to 0, and then decrements `i` by 1 after each iteration. Since `i` is already less than 10, it will never reach the termination condition, resulting in an infinite loop.

    Rate this question:

  • 29. 

    What is the value of x after the following code fragment executes? float x = 36.0; x = sqrt(x);

    • A.

      36.0

    • B.

      6.0

    • C.

      3.0

    • D.

      2.456

    Correct Answer
    B. 6.0
    Explanation
    The code fragment calculates the square root of the initial value of x, which is 36.0. The square root of 36.0 is 6.0. Therefore, the value of x after the code executes is 6.0.

    Rate this question:

  • 30. 

    What is the output of the following program fragment? cout << pow(4,2) << endl;

    • A.

      4

    • B.

      2

    • C.

      8

    • D.

      16

    Correct Answer
    D. 16
    Explanation
    The program fragment uses the pow() function to calculate the result of 4 raised to the power of 2, which is 16. The result is then printed to the console followed by an endline character.

    Rate this question:

  • 31. 

    1. Which boolean operation is described by the following table?
    A B Operation True True True True False False False True False False False False  

    • A.

      Or

    • B.

      And

    • C.

      Not

    • D.

      None of the above

    Correct Answer
    B. And
    Explanation
    The correct answer is "and". This is because the table shows that the output is only true when both inputs A and B are true. If either one or both of the inputs are false, the output is false. This behavior aligns with the logical "and" operation, where the result is true only if both conditions are true.

    Rate this question:

  • 32. 

    1. Which boolean operation is described by the following table?
    A B Operation True True True True False True False True True False False False

    • A.

      Or

    • B.

      And

    • C.

      Not

    • D.

      None of the above

    Correct Answer
    A. Or
    Explanation
    The boolean operation described by the table is "or". This is because the result is true when either A or B (or both) are true. When both A and B are true, the result is true. When only one of A or B is true, the result is also true. However, when both A and B are false, the result is false.

    Rate this question:

  • 33. 

    What is the value of x after the following statement? float x; x = 3.0 / 4.0 + 3  + 2 / 5

    • A.

      5.75

    • B.

      4.75

    • C.

      1.75

    • D.

      3.75

    Correct Answer
    D. 3.75
    Explanation
    The value of x is 3.75. In the given statement, the expression is evaluated from left to right. First, the division operation 3.0 / 4.0 is performed, resulting in 0.75. Then, the addition operation 0.75 + 3 is performed, resulting in 3.75. Finally, the division operation 2 / 5 is performed, resulting in 0.4, but since the variable x is of type float, the result is converted to a float before being assigned to x. Therefore, the final value of x is 3.75.

    Rate this question:

  • 34. 

    What is the value of x after the following statements? double x; x = 0; x += 3.0 * 4.0; x -= 2.0;

    • A.

      22.0

    • B.

      12.0

    • C.

      10.0

    • D.

      14.0

    Correct Answer
    C. 10.0
    Explanation
    The variable x is declared as a double and initialized to 0. Then, the value of x is updated by multiplying 3.0 and 4.0, which results in 12.0. Finally, 2.0 is subtracted from x, resulting in a final value of 10.0.

    Rate this question:

  • 35. 

    What is the value of x after the following statements? int x; x = 15 %4;

    • A.

      15

    • B.

      4

    • C.

      3

    • D.

      3.75

    Correct Answer
    C. 3
    Explanation
    The value of x after the given statements is 3. The expression "15 % 4" calculates the remainder when 15 is divided by 4, which is 3. Therefore, the value of x is assigned as 3.

    Rate this question:

  • 36. 

    An algorithm is

    • A.

      The inputs and outputs of a program

    • B.

      The part of the computer that does the processing

    • C.

      A finite set of steps to solve a problem

    • D.

      A complete computer program

    Correct Answer
    C. A finite set of steps to solve a problem
    Explanation
    The correct answer is "A finite set of steps to solve a problem." An algorithm refers to a step-by-step procedure or a finite set of instructions that are followed to solve a problem or perform a specific task. It is a systematic approach that outlines the necessary steps or operations needed to achieve a desired outcome. Algorithms can be implemented in various programming languages and are crucial in computer science and problem-solving.

    Rate this question:

  • 37. 

    Which of the following is not a phase of the program-design process?

    • A.

      Problem-solving

    • B.

      Implementation

    • C.

      Marketing the final program

    Correct Answer
    C. Marketing the final program
    Explanation
    The program-design process involves several phases, including problem-solving, implementation, and marketing the final program. Problem-solving refers to identifying and defining the problem that the program aims to solve. Implementation involves the actual development and coding of the program. Marketing the final program refers to promoting and distributing the program to the intended audience. However, marketing the final program is not a phase of the program-design process as it focuses on the post-development stage and is more related to the business and marketing aspects rather than the design and development of the program itself.

    Rate this question:

  • 38. 

    Which of the following is not part of the Software Life Cycle?

    • A.

      Analysis

    • B.

      Design

    • C.

      Data Entry

    • D.

      Implementation

    • E.

      Testing

    Correct Answer
    C. Data Entry
    Explanation
    Data Entry is not part of the Software Life Cycle because it refers to the process of inputting data into a computer system, which is not a specific phase or activity in the software development process. The Software Life Cycle typically includes phases such as Analysis, Design, Implementation, and Testing, which are focused on the development and testing of software applications. Data Entry, on the other hand, is a separate task that involves entering data into a system and does not directly contribute to the software development process.

    Rate this question:

  • 39. 

    Which of the following is not an example of a program bug?

    • A.

      Run-time error

    • B.

      Operator error

    • C.

      Syntax error

    • D.

      Logic error

    Correct Answer
    B. Operator error
    Explanation
    An operator error is not considered a program bug because it is caused by a mistake made by the user, rather than a flaw in the program's code. Operator errors occur when the user enters incorrect or inappropriate input, or performs an action in an unintended manner. These errors are typically the result of human error or misunderstanding, rather than a problem with the program itself.

    Rate this question:

  • 40. 

    The set of instructions that a computer will follow is known as:

    • A.

      Hardware

    • B.

      Algorithm

    • C.

      Program

    • D.

      CPU

    Correct Answer
    C. Program
    Explanation
    A program refers to a set of instructions that a computer follows to perform a specific task or solve a problem. It is a sequence of commands that tells the computer what operations to execute and in what order. Programs are created by programmers using programming languages and are stored in the computer's memory or storage devices. The computer reads and executes these instructions to carry out the desired tasks. Therefore, the correct answer is Program.

    Rate this question:

  • 41. 

    Which of the following is not a valid identifier?

    • A.

      Return

    • B.

      MyInt

    • C.

      MyInteger

    • D.

      Total3

    Correct Answer
    A. Return
    Explanation
    The identifier "return" is not valid because it is a reserved keyword in many programming languages, including Python. Reserved keywords have a special meaning in the language and cannot be used as identifiers for variables, functions, or other elements of the code. Therefore, "return" cannot be used as a variable name in this context.

    Rate this question:

  • 42. 

    What is the value of x after the following statements? int x, y, z; y = 10; z = 3; x = y * z + 3;

    • A.

      Garbage

    • B.

      60

    • C.

      30

    • D.

      33

    Correct Answer
    D. 33
    Explanation
    The value of x is 33. This is because the expression y * z + 3 is evaluated first, which is equal to 30 + 3. Therefore, x is assigned the value of 33.

    Rate this question:

  • 43. 

    What is the value of x after the following statements? int x; x = x + 30;

    • A.

      0

    • B.

      30

    • C.

      33

    • D.

      Garbage

    Correct Answer
    D. Garbage
    Explanation
    The value of x is uninitialized before the statement x = x + 30. Therefore, when we try to add 30 to x, we are essentially adding 30 to an unknown value. This results in an undefined or garbage value for x.

    Rate this question:

  • 44. 

    What is the output of the following code? float value; value = 33.5; cout << value << endl;

    • A.

      33.5

    • B.

      33

    • C.

      Value

    • D.

      Garbage

    Correct Answer
    A. 33.5
    Explanation
    The code initializes a variable named "value" as a float with the value 33.5. Then, it prints the value of "value" followed by an end line character. Therefore, the output of the code will be 33.5.

    Rate this question:

  • 45. 

    Which of the following statements is NOT legal?

    • A.

      Char ch='b';

    • B.

      Char ch='0';

    • C.

      Char ch=65;

    • D.

      Char ch="cc";

    Correct Answer
    D. Char ch="cc";
    Explanation
    The statement "char ch="cc";" is not legal because it is assigning a string value to a char variable. In Java, a char can only hold a single character, not a string of characters.

    Rate this question:

  • 46. 

    What is the value of choice after the following statements? void getChoice(int& par_choice, in par_count); int choice, count=3;   getChoice(choice, count);   void getChoice(int& par_choice, in par_count) {             if(par_count<0)                         par_choice =0;             if(par_count = 0)                         par_choice=-1;             else                         par_choice=99;             return; }

    • A.

      3

    • B.

      0

    • C.

      -1

    • D.

      99

    Correct Answer
    D. 99
    Explanation
    The value of choice after the given statements is 99. This is because the function getChoice is called with the arguments choice and count. Inside the function, there are conditional statements. If par_count is less than 0, par_choice is assigned 0. If par_count is equal to 0, par_choice is assigned -1. Otherwise, par_choice is assigned 99. Since count is 3, which is not less than 0 or equal to 0, the else condition is executed and par_choice is assigned 99. Therefore, the value of choice after the statements is 99.

    Rate this question:

  • 47. 

    What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost);   float tax = 0.0,   subtotal = 0.0;   calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal        << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment   void calculateCost(int count, float& subTotal, float taxCost) {       if ( count < 10)       {                   subTotal = count * 0.50;       }       else       {                   subTotal = count * 0.20;       }       taxCost = 0.1 * subTotal; }

    • A.

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.30;

    • B.

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.00;

    • C.

      The cost for 15 items is 0.00, and the tax for 3.00 is 0.30;

    • D.

      The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;

    Correct Answer
    D. The cost for 15 items is 3.00, and the tax for 3.00 is 0.00;
    Explanation
    The function calculateCost takes three parameters: count, subTotal, and taxCost. It calculates the subtotal based on the count, where if the count is less than 10, the subtotal is count * 0.50, otherwise it is count * 0.20. After calculating the subtotal, it calculates the taxCost as 0.1 * subTotal. In the given function call, count is 15, so the else condition is executed and the subtotal is calculated as 15 * 0.20 = 3.00. The taxCost is then calculated as 0.1 * 3.00 = 0.30. Therefore, the output is "The cost for 15 items is 3.00, and the tax for 3.00 is 0.30."

    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
  • May 11, 2011
    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.