Note: THIS IS NOT INTENDED AS A STUDY GUIDE, BUT ONLY TO GIVE YOU AN IDEA OF THE EXAM FORMAT AND TYPE OF QUESTIONS. ----------------------------------------------------------------------------- True-False (1 points each) Circle TRUE or FALSE after each question. 1. The rules of C++ require that you write a default constructor for every class. TRUE FALSE 2. The packaging of data and functions into a class is called decapsulation. TRUE FALSE 3. Constructors cannot be overloaded. TRUE FALSE 4. Destructors cannot be overloaded. TRUE FALSE 5. The use of a reference as a function argument guarantees that the actual argument specified in main() (or other calling function) cannot be modified. TRUE FALSE 6. It is illegal to make an assignment to a const variable. TRUE FALSE 7. The return type of a constructor can be void or it can be omitted. TRUE FALSE 8. The delete operator is used to dynamically allocate an array. TRUE FALSE 9. Pointers to objects are allowed in C++, but only when the object is const. TRUE FALSE 10. In the textbook's implementation of quicksort, the partition element is chosen randomly. TRUE FALSE Multiple Choice (3 points each) For each question, write the letter of the best answer: _____ 1. Hiding the internal workings of a class is achieved through the use of: (a) reference parameters (b) access specifiers (c) curly braces (d) indirection _____ 2. An inline function: (a) is limited to a single statement. (b) avoids the overhead of a function call. (c) cannot use the conditional operator. (d) All of the above _____ 3. A key difference between procedure-oriented and object-oriented is: (a) the type of syntax supported by programming languages. (b) the use of references rather than pointers. (c) the way that a software application is decomposed. (d) the use of makefiles and separate complation. _____ 4. Using references as parameters to a function: (a) is allowed only in member functions. (b) avoids having to make temporary copies of the actual arguments. (c) allows multiple signatures for the same function. (d) prevents a function from changing the actual arguments. _____ 5. Four types of scope in C++ are: (a) class, local, block, statement (b) class, function, global, program (c) class, file, function, local (d) class, compiler, file, function _____ 6. A type of algorithm that reduces a problem into several smaller problems of the same nature would be called: (a) iterative (b) object-oriented (c) recursive (d) encapsulated _____ 7. The keyword this is used: (a) as a pointer to the host object in a member function. (b) as a pointer to the block of memory allocated by the new operator. (c) as a pointer to indicate which overloaded constructor is being used. (d) as a pointer to the member function currently being invoked. _____ 8. Suppose that there is exactly one function called Whatever() and that function has the following prototype: void Whatever (int a, int b = 3); Which of the following statements would result in a compiler error: (a) Whatever (1, 3); (b) Whatever (1.0); (c) Whatever (1); (d) Whatever ( ); _____ 9. If a is the name of an array, which of the following is equivalent to a[5]: (a) a * 5 (b) *(a + 5) (c) a + 5 * sizeof(a) (d) (*a) + 5 _____ 10. Which of the following is NOT a valid type of pointer arithmetic: (a) pointer + integer (b) pointer - integer (c) pointer + pointer (d) pointer - pointer Determine the output of the following program. (25 points) #include class Something { private: int _num; char _letter; public: Something (int a = 3, char c = 'A'); inline int GetNum (); int Whatever (); char operator + (const Something& s); }; Something::Something (int a, char c) { _num = a; _letter = c; } inline int Something:: GetNum() { return _num; } int Something::Whatever() { int result = 0; for (int k = 1; k <= _num; ++k) { result += k; } return result; } char Something::operator + (const Something& s) { return (_letter + s._num); } int SomethingElse (int val) { if (val == 1) { return val; } else { return ( val * SomethingElse (val - 1) ); } } int main() { Something x; Something y (2); Something z (5, 'M'); cout << z.Whatever() << endl; cout << SomethingElse (z.GetNum()) << endl; cout << (x + y) << endl; cout << (y + x) << endl; cout << (x + z) << endl; return 0; } For the class shown below, insert declarations into the class body for: (a) destructor (2 points) (b) copy constructor (4 points) (c) overloaded assignment operator (4 points) class Student { private: char * _name; long _ssn; public: Student (char * n = John Doe , long id); }; Student::Student (char * n, long id) { _ssn = id; _name = new char [ strlen (n) + 1 ]; strcpy (_name, n); } Write the destructor: (5 points) Write the copy constructor: (10 points) Write the overloaded assignment operator: (10 points)