Midterm Exam 3 March 11, 2015 Name: ______________________________
Section 1: Multiple Choice Questions (30 pts total, 2 pts each) Q1: Which of the following best describes the array name n in the declaration int n[10];? a. n is a nonconstant pointer to nonconstant data. b. n is a nonconstant pointer to constant data. c. n is a constant pointer to nonconstant data. d. n is a constant pointer to constant data. ANS: c. n is a constant pointer to nonconstant data. Q2: What method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation: a. A nonconstant pointer to nonconstant data. b. A nonconstant pointer to constant data. c. A constant pointer to nonconstant data. d. A constant pointer to constant data. ANS: d. A constant pointer to constant data. Q3: A class-scope variable hidden by a block-scope variable can be accessed by preceding the variable name with the class name followed by: a. :: b. : c. . d. -> ANS: a. :: Q4: Utility functions: a. Are private member functions that support operations of the class’s other member functions. b. Are part of a class’s interface. c. Are intended to be used by clients of a class. d. Are a type of constructor. ANS: a. Are private member functions that support operations of the class’s other member functions. Q5: Assuming the following constructor is provided for class Time explicit Time( int = 0, int = 0, int = 0 ); which of the following is not a valid way to initialize a Time object? a. Time t1; b. Time t2{ 22, 40 }; c. Time t3( 22, 40 ); d. (a), (b) and (c) are all valid ways to initialize a Time object. ANS: d. (a), (b) and (c) are all valid ways to initialize a Time object. Q6: Which of the following is not true of a constructor and destructor of the same class? a. They both have the same name aside from the tilde (~) character. b. They are both usually called once per object created. c. They both are able to have default arguments. d. Both are called automatically, even if they are not explicitly defined in the class. ANS: c. They both are able to have default arguments.
Q7: If a member function of a class already provides all or part of the functionality required by a constructor or another member function then: a. Copy and paste that member function’s code into this constructor or member function. b. Call that member function from this constructor or member function. c. That member function is unnecessary. d. This constructor or member function is unnecessary. ANS: b. Call that member function from this constructor or member function. Q8: Given the class definition: class CreateDestroy { public: CreateDestroy() { cout