C++ and UML - Exam Prep.txt

  1. With reference to Figure 6, which kind of icon would you use to represent a communication path between systems or between a human and a system? Choose only one option.

    Image Upload 2



    B) C
  2. With reference to Figure 6, which kind of icon would you use to represent an object that coordinates a system process, creates objects or retrieves objects? Choose only one option.

    Image Upload 4



    A) A
  3. In Figure 7, what does the arrow hitting the p:PMember box indicate? Choose only one option.

    Image Upload 6




    E) p is created at that moment in time.
  4. What kind of diagram is shown in Figure 7? Choose only one option.  

    Image Upload 8







    G) Sequence diagram.
  5. Which of the following statements are true? Choose all options that apply.  




    • A) Most superclasses are abstract. 
    • d) Composition is preferable to inheritance.
  6. In UML diagrams, how are abstract classes distinguished from concrete classes? Choose only one option.  




    B) Labels on abstract classes are shown in italics.
  7. What is "design by contract"? Choose only one option.  




    B) Designing code as if there were a contract between an object that sends a message and the object that receives it.
  8. What does the term "polymorphism" refer to? Choose all options that apply.  

    a) The ability of a variable to point at different classes of object at different times.  
    b) The fact that a message with the same signature can invoke different methods at different times.  
    c) All object-oriented programming languages are different.  
    d) All object-oriented methodologies use a different notation.
    • a) The ability of a variable to point at different classes of object at different times.  
    • b) The fact that a message with the same signature can invoke different methods at different times.
  9. In UML diagrams, how are classmessages distinguished from instance messages? Choose only one option.  




    A) Class messages are underlined.
  10. What is a "generic" class? Choose only one option.  



    A) A class that has other classes as parameters.
  11. With reference to Figure 8, what is Z? Choose only one option.

    Image Upload 10





    A) An interface.
  12. What is an "abstract" class? Choose only one option.  





    E) A class with at least one undefined message.
  13. What are the traditional steps in software production? Choose all options that apply.  

    a) Maintenance.  
    b) Design.  
    c) Iteration.  
    d) Incrementation.  
    e) Deployment.  
    f) Analysis.  
    g) Requirements capture.  
    h) Testing.  
    i) Reuse.  
    j) Implementation. 
    k) Specification.
    • a) Maintenance.  
    • b) Design.  
    • e) Deployment.  
    • f) Analysis.  
    • g) Requirements capture.  
    • h) Testing. 
    • j) Implementation. 
    • k) Specification.
  14. What is "encapsulation"? Choose only one option.  




    A) Ensuring that the data inside an object can only be accessed via operations.
  15. In UML, which diagrams are used to show messages sent between objects? Choose all options that apply.  






    • B) Communication diagrams.
    • e) Sequence diagrams.
  16. What is meant by the term "deadlock"? Choose only one option.  



    B) An object is waiting for a resource, which is being used by an object waiting for a resource used by the first object.
  17. Servlets are a direct replacement for what? Choose only one option.  





    A) CGI scripts.
  18. Which of the following UML artifacts is used to show the steps involved in getting value from a system? Choose only one option. 






    A) Use cases.
  19. What is an association class? Choose only one option.  



    C) It adds attributes and/or behaviour to an association between two other classes.
  20. Which of the following terms best describes the case where a Stack class is implemented using an internal instance of List? Choose only one option.  





    A) Composition.
  21. What is a "thread"? Choose only one option.  



    B) An activity within a process that shares memory with other activities.
  22. All of the following are true about classes, except:   




    C) The first class in any C++ program is main.
  23. C++ functions other than main are executed:   




    C) When they are explicitly called by another function.
  24. Function headers contain all of the following except:    




    C) Left brace.
  25. An object creation expression contains:    




    A) All of the above.
  26. Calling a member function of an object requires which item?   




    A) The dot separator.
  27. In the UML, the top compartment of the rectangle modeling a class contains:    




    A) The class’s name.
  28. What is the name of the values the method call passes to the method for the parameters?   




    D) Arguments.
  29. Assuming that text is a variable of type string, what will be the contents of text after the statement cin >> text; is executed if the user types “Hello World!” and then presses Enter?




    D)   Hello
  30. Multiple parameters are separated by what symbol?   




    C) Commas.
  31. Attributes of a class are also known as:   




    C) Data members.
  32. What is the default initial value of a String in C++?   




    A) ""
  33. What type of member functions allow a client of a class to assign values to private data members?  




    B) Set member functions.
  34. A default constructor has how many parameters?  




    D) 0.
  35. A constructor can specify the return type:   




    C) A constructor cannot specify a return type.
  36. The compiler will implicitly create a default constructor if:  




    A) The class does not define any constructors.
  37. A header file is typically given the filename extension: 




    C)  .h.
  38. Assuming that GradeBook.h is found in the current directory and the iostream header file is found in the C++ Standard Library header file directory, which of the following preprocessor directives will fail to find its desired header file?  




    • A) #include .  OR
    • b) #include .  

    (Typo somewhere in the original print of this question.)
  39. In the source-code file containing a class’s member function definitions, each member function definition must be tied to the class definition by preceding the member function name with the class name and ::, which is known as the:  




    C) Binary scope resolution operator.
  40. When compiling a class’s source code file (which does not contain a main function), the information in the class’s header file is used for all of the following, except:  




    B) Determining the correct amount of memory to allocate for each object of the class.
  41. When a client code programmer uses a class whose implementation is in a separate file from its interface, that implementation code is merged with the client’s code during the:   




    B) Linking phase.
  42. To execute multiple statements when an if statement’s condition is true, enclose those statements in a pair of:  




    A) Braces, { }.
  43. Assuming that the string object text contains the string “Hello!!!”, the expression text.substr( 2 , 5 ) would return a string object containing the string: 




    B)  “llo!!”.
  44. A solid line representing an association between two classes can be accompanied by any of the following details, except:  




    B) An aggregation relationship with another association line.
  45. A composition or “has-a” relationship is represented in the UML by:  




    A) Attaching a solid diamond to the association line.
  46. Specifying the order in which statements are to be executed in a computer program is called:   




    D) Program control.
  47. Which of the following is true of a pseudocode program?  




    B) They help the programmer “think out” a program.
  48. Pseudocode does not include:  




    C) Declarations.
  49. Which of the following encompasses the other three?  




    C) Control structure.
  50. In an activity diagram for an algorithm, what does a solid circle surrounded by a hollow circle represent?   




    B) Final state.
  51. Which of the following is a double-selection statement?  




    A)  if…else.
  52. Which of the following is a repetition structure?    




    D) do…while.
  53. If grade has the value of 60, what will the following code print? 

    If ( grade >= 60 )
          Cout << "Passed";
     




    C)  c. Passed.
  54. The data type bool:  




    D) Can take on values true and false.
  55. The conditional operator (?:):  




    A) Is the only ternary operator in C++.
  56. Which of the following does not perform the following task: print correct if answer is equal to 7 and incorrect if answer is not equal to 7?  

    a) If ( answer == 7 )
          cout << "correct";
        else
          cout << "incorrect";
    b) answer == 7 ? cout << "correct" : cout << "incorrect"; 
    c) cout << ( answer == 7 ? "correct" : "incorrect" ); 
    d) cout << answer == 7 ? "correct" : "incorrect";
    c) cout << ( answer == 7 ? "correct" : "incorrect" ); 

    or  

    d) cout << answer == 7 ? "correct" : "incorrect";

    Somewhere there is a typo in the original publication of this question example.
  57. A block:  




    D) Is a compound statement.
  58. What is wrong with the following while loop? 

    while ( sum <= 1000 )
    sum = sum – 30;




    C) sum = sum – 30 should be sum = sum + 30 or else the loop may never end.
  59. How many times will the following loop print hello? 

    i = 1;
    while ( i <= 10 )
               cout << "hello";
      



    D)  An infinite number of times.
  60. An uninitialized local variable contains:  




    A) The value last stored in the memory location reserved for that variable.
  61. Using a loop’s counter-control variable in a calculation after the loop ends often causes a common logic error called:  




    A) An off-by-one error.
  62. Indefinite repetition is controlled by a:   




    D) Sentinel value.
  63. A fatal logic error can be caused by:  




    A) An attempt to divide by zero.
  64. In indefinite repetition, an input value:  




    D) Should always be evaluated before being processed.
  65. What is the final value of x after performing the following operations? 

    int x = 21;
    double y = 6;
    double z = 14;
    y = x / z;
    x = 5.5 * y;
     



    C)  8.
  66. Which operation does not take place in the following example?

    int x = 21;
    double y = 6;
    double z = 14;
    y = x / z;
    x = 5.5 * y;
      



    B) Implicit conversion.
  67. Having a loop within a loop is known as:   




    B) Nesting.
  68. To handle situations where a loop must reinitialize a variable at the beginning of each iteration, such reinitialization could be performed by:  




    C) A declaration inside the loop body.
  69. If x initially contains the value 3, which of the following sets x to 7? 




    A) x += 4;
  70. Assuming that x and y are equal to 3 and 2, respectively, after the statement x -= y executes, the values of x and y will be: 




    B)  x: 1; y: 2.
  71. Which of the following will not increment c by 1?   




    B)  c + 1;.
  72. Assuming that x is equal to 4, which of the following statements will not result in y containing the value 5 after execution?  




    C) y = x++;.
  73. Which of the following operations has the highest precedence?  




    A) Postincrement.
  74. Which of the following is not a piece of information that could be found in the attribute compartment of a class’s rectangle in the UML?  




    A) The attribute’s memory location.
  75. A class-type attribute is best modeled by: 




    D)  A composition association.
  76. Which of the following does counter-controlled repetition require?  




    B) Counter-controlled repetition requires all of these mentioned.
  77. The statement;

    while ( --counter >= 1 )
    counter % 2 ? cout << "A" : cout << "B";

    cannot be rewritten as:

    a)  while ( --counter >= 1 )
    counter % 2 == 0 ? cout << "B" : cout << "A";.

    b)  while ( counter > 1 )
    {
    --counter;

    if ( counter % 2 )
    cout << "A";
    else
    cout << "B";
    }.
     
    c)  while ( counter >= 1 )
    if ( counter % 2 )
    cout << "A";
    else
    cout << "B";
    --counter;

    d)  while ( --counter >= 1 )
    if ( counter % 2 )
    cout << "A";
    else
    cout << "B";.
    • c)  while ( counter >= 1 )
    • if ( counter % 2 )
    • cout << "A";
    • else
    • cout << "B";
    • --counter;
  78. Which of the following is a bad programming practice? 




    C) Using floating-point values for counters in counter-controlled repetition.
  79. If a variable is declared in the initialization expression of a for structure, then:  




    C) The scope of the variable is restricted to that particular for loop.
  80. Which of the following is not true?  




    C) You must declare the control variable outside of the for loop.
  81. Consider the execution of the following for loop;

    for (int x = 1; x < 5; increment )
    cout << x + 1 << endl;

    If the last value printed is 5, which of the following might have been used for increment?  




    D) Any of these mentioned.
  82. Which of the following for headers is not valid?  




    D) for ( int i = 0; int j = 5; ; i++ ).
  83. float and double variables should be used:  




    D) As imprecise representations of decimal numbers.
  84. Which of the following is a parameterized stream manipulator used to format output?    




    B) setw.
  85. If a do…while structure is used:  




    B) The body of the loop will execute at least once.
  86. What will the following program segment do?

    int counter = 1;
    do {
         cout << counter << " ";
    } while ( ++counter <= 10 );
      



    B) Print the numbers 1 through 10.
  87. A switch statement should be used:  




    B) As a multiple-selection structure.
  88. In a switch structure:  




    C) Multiple actions do not need to be enclosed in braces.
  89. Which of the following is correct when labeling cases in a switch structure?  




    D) case 1.
  90. switch can be used to test:  




    A) int constants.
  91. Which of the following data types can be used to represent integers?  




    D) All of these mentioned.
  92. Which of the following is false?  




    C) continue and break statements may be embedded within all C++ structures.
  93. Which of the following is false?  




    B) You should always try to write the fastest, smallest code possible before attempting to make it simple and correct.
  94. In C++, the condition ( 4 > y > 1 ):  




    D) Does not evaluate correctly and should be replaced by ( 4 > y && y > 1 ).
  95. The OR (||) operator:  




    C) Stops evaluation upon finding one condition to be true.
  96. An operator that associates from right to left is:   




    D) ?:.
  97. The expression if ( num != 65 ) cannot be replaced by:  




    B) if ( !( num – 65 ) ).
  98. An example of a unary operator is:  




    A) The ! logical operator.
  99. Variables are also known as:  




    C) lvalues, but can be used as rvalues.
  100. Consider the following code, assuming that x is an int with an initial value of 12;

    if( x = 6 )
    cout << x;

    What is the output?  




    B) 6.
  101. Of the following, which is not a logic error?   




    C) Using commas instead of the two required semicolons in a for header.
  102. The ____________, __________ and ____________ are the only three forms of control necessary.  




    C) sequence, selection, repetition.
  103. Which of the following is not one of the C++ control structures?   




    C) main.
  104. Which of the following is not one the rules for forming structured programs?  




    D) Any transition arrow can be reversed.
  105. Which of the following is not a part of a UML state diagram?  




    D) Fractions beside each state indicating the likelihood of entering that state.
  106. An activity diagram for modeling the actions involved in executing a balance inquiry transaction using the BalanceInquiry object should not include:  




    B) Receiving the user’s main menu input indicating a desire to inquire the amount of his or her balance.
  107. All of the following are true of functions except:  




    A) The definition of a function usually is visible to other functions.
  108. Functions can:  




    D) Do any of these mentioned.
  109. All math library functions:  




    D) Are global functions.
  110. Which of the following expressions returns the trigonometric sine of x?  




    B) sin( x ).
  111. Which of the following is not included in .math?  




    • D) log.
    • a) ln.
  112. The function prototype double mySqrt( int x );   




    C) Declares a function called mySqrt which takes an integer as an argument and returns a double.
  113. Using the following function definition, the parameter list is represented by:

     A B ( C )
    {
         D
    }
      



    A) C.
  114. A function prototype does not have to:   




    C) Include parameter names.
  115. A function prototype can always be omitted when:  




    C) A function is defined before it is first invoked.
  116. Converting from type ________ to type ________ will result in the loss of data.  




    B) int, char.
  117. Each standard library has a corresponding:   




    B) Header file.
  118. Which of the following C++ Standard Library header files does not contain a C++ Standard Library container class?  




    C) <string>.
  119. The rand function generates a data value of the type:  




    B) unsigned int.
  120. A variable that can only have values in the range 0 to 65535 is a:  




    A) Two-byte unsigned int.
  121. In the expression n = x + rand() % y;  




    B) y is the scaling value.
  122. srand:  




    D) Can use the time function’s return value as an optimal seed value.
  123. Enumeration constants: 




    D) Must have unique identifiers.
  124. An identifier’s storage class:




    C) Determines the period during which that identifier exists in memory.
  125. Depending on the circumstances, the compiler may ignore the storage class specifier:  




    A) register.
  126. Which of the following is not true of static local variables?  




    C) They are accessible outside of the function in which they are defined.
  127. Labels are the only identifiers with:  




    A) Function scope.
  128. The only identifiers that can be reused elsewhere in a program without any ambiguity are:  




    A) Those in the parameter list of a function prototype.
  129. An activation record will be popped off the function call stack whenever:  




    A) A function returns control to its caller.
  130. Which of the following is not included in a function’s activation record? 




    D) The name of the function.
  131. Which of the following is false about the following function prototype? 

    void functionA( void );  




    D) It could have been written functionA( void );.
  132. The inline keyword:  




    B) Can reduce a function’s execution time but increase program size.
  133. When an argument is passed-by-value, changes in the calling function __________ affect the original variable’s value; when an argument is passed call-by-reference, changes __________ affect the original variable’s value.  




    B) Do not, do.
  134. A reference parameter:  




    C) Both (a) and (b).
  135. Call-by-reference can achieve the security of call-by-value when:  




    B) The const qualifier is used.
  136. In regards to default arguments, which of the following is false?  




    C) Default values cannot be global variables or function calls.
  137. If the function int volume( int x = 1, int y = 1, int z = 1 ); is called by the expression volume( 3 ), how many default arguments are used?   




    A) Two.
  138. The unary scope resolution operator is used:   




    C) To access a global variable when a local variable of the same name is in scope.
  139. Which of the following does the C++ compiler not examine in order to select the proper overloaded function to call?  




    A) The return type of the function.
  140. If a function’s program logic and operations are identical for each data type it could receive as argument(s) then a __________ should be used.  




    A) Function template.
  141. A recursive function is a function that:  




    C) Calls itself, directly or indirectly.
  142. Assuming the following pseudocode for the Fibonacci series, what is the value of the 5th Fibonacci number (fibonacci ( 5 ))? 

    fibonacci( 0 ) = 0
    fibonacci( 1 ) = 1
    fibonacci( n ) = fibonacci( n – 1 ) + fibonacci( n – 2 )
       



    D) 5.
  143. Recursion is to the base case as iteration is to what: 




    D) Failure of the loop continuation test.
  144. An array is not:   




    C) Made up of different data types.
  145. Assuming that int a has a value of 3 and that integer array b has 7 elements, what is the correct way to assign the value of the third element plus 3, to the fifth element of the array:  




    B) b[ a + 1 ] = b[ a - 1 ] + 3;.
  146. Which of the following is not true?  




    C) A subscript cannot be an expression.
  147. Which statement would be used to declare a 10-element integer array c?  




    D) int c[ 10 ];.
  148. Which of the following is not a correct way to initialize an array?  




    D) int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };.
  149. Constant variables:  




    D) Can be used to specify array sizes, thereby making programs more scalable.
  150. Referencing elements outside the array bounds:    




    B) Can result in changes to the value of an unrelated variable.
  151. Strings represented as character arrays cannot:   




    A) Grow or shrink dynamically.
Author
caldreaming
ID
289101
Card Set
C++ and UML - Exam Prep.txt
Description
A combination of question for preparing for C++ and UML exams
Updated