True-False (1 point each) Circle TRUE or FALSE after each question. 1. Recursion is inherently more efficient than iteration. TRUE FALSE 2. The performance of bubble sort is O (log n). TRUE FALSE 3. The ifstream class is declared in the iostream.h header file. TRUE FALSE 4. Constructors cannot be overloaded. TRUE FALSE 5. Destructors cannot be overloaded. TRUE FALSE 6. Destructors cannot be virtual. TRUE FALSE 7. Quicksort is an example of a comparison-based sorting algorithm. TRUE FALSE 8. Quicksort is a recursive sorting algorithm. TRUE FALSE 9. Given: const char* ptr; It is possible to change what ptr points to but not the value of ptr. TRUE FALSE 10. The << and >> operators can only be used with the stream objects cin, cout, and cerr. TRUE FALSE 11. The function 3n2 is O(n2). TRUE FALSE 12. The advantages of dynamic binding cannot be achieved when non-member functions are involved. TRUE FALSE 13. It is always acceptable for a base class pointer to point to a derived class object. TRUE FALSE 14. Inheritance is also referred to as the "is-a-child-of" relationship. TRUE FALSE 15. The chief activity of object-oriented analysis and design is referred to as functional decomposition. TRUE FALSE Multiple Choice (2 points each) For each question, write the letter of the best answer: _____ 1. 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. _____ 2. 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. _____ 3. O(n) is also referred to as __________ growth. (a) linear (b) unit (c) constant (d) bounded _____ 4. Which of the following is NOT a type of recursion? (a) head (b) tail (c) indirect (d) tree _____ 5. Given: ifstream infile ("abc.txt"); Which of the following is NOT a correct way to check that the "abc.txt" file has been successfully opened? (a) if ( !infile ) (b) if ( !infile.open() ) (c) if ( !infile.good() ) (d) if ( infile.fail() ) _____ 6. Data members to be shared by all objects of a class should be declared as: (a) private (b) global (c) extern (d) static _____ 7. 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 _____ 8. 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 _____ 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 (d) (*a) + 5 _____ 10. Which of the following demonstrates use of the ios::showbase flag: (a) 1.23e4 (b) +1234 (c) 01234 (d) 1234 (base=10) _____ 11. Which of the following is NOT a valid type of pointer arithmetic: (a) pointer + integer (b) pointer - integer (c) pointer + pointer (d) pointer - pointer _____ 12. The signature of a function consists of: (a) the function name and return type (b) the function name, parameters, and return type (c) the function name and parameters (d) the parameters and return type _____ 13. An unsuccessful binary search on an array of 212 sorted items takes approximately: (a) 6 comparisons (b) 12 comparisons (c) 24 comparisons (d) 1024 comparisons _____ 14. Which of the following sorting routines has O(n lg n) performance? (a) bubble sort (b) insertion sort (c) merge sort (d) selection sort _____ 15. Which of the following was NOT involved in the creation of the Unified Modeling Language (UML)? (a) Grady Booch (b) Ivar Jacobson (c) James Rumbaugh (d) Paul Wang Short Answers (2 points each) Three uses of the member initialization list in C++ are: (1) (2) (3) The sections of a class in C++ are: (1) (2) (3) A tree is a set of vertices and ______________ . In a tree, a vertex without any children is called ______________________________ . __________________________ refers to two or more versions of a function with the same name but different signature. An abstract class contains one or more ______________________________________ . Determine the output of the following program. (10 points) #include class Base { private: int _x; protected: int _y; public: Base() : _x(4), _y(6) { } virtual int GetX() { return _x; } int Foo() { return _y; } }; class Derived : public Base { private: int _x; public: Derived() : _x(2) { } virtual int GetX() { return _x; } int Foo() { return _y + 8; } }; void main() { Base b1, *b2, *b3; Derived d1, *d2; b2 = new Base(); b3 = new Derived(); d2 = new Derived(); cout << b1.GetX() << " " << b1.Foo() << endl; cout << d1.GetX() << " " << d1.Foo() << endl; cout << b2->GetX() << " " << b2->Foo() << endl; cout << b3->GetX() << " " << b3->Foo() << endl; cout << d2->GetX() << " " << d2->Foo() << endl; } Determine the output of the following program. (5 points) #include #include void main() { int x = 36; cout.fill ('*'); cout << setw (6) << x << endl; cout << hex << x << endl; } Show the binary search tree that results from inserting the following values into a empty tree: (5 points) 79, 69, 84, 67, 85, 77, 80 Fill in the missing statements. (15 points) class X { private: int _x; int _y; public: X (int a = 0, int b = 0) : _x(a), _y(b) { } }; class XX { private: X ** _ptr; int _num; public: XX (int n); ~XX(); XX (const XX& xr); }; XX::XX (int n) { _num = n; // One statement missing here for (int i = 0; i < _num; ++i) { _ptr[i] = new X(); } } XX::~XX() { for (int i = 0; i < _num; ++i) { // One statement missing here } // One statement missing here } // This copy constructor should copy the objects // being pointed to, not just the pointers. XX::XX (const XX& xr) { // One statement missing here _ptr = new X* [_num]; for (int i = 0; i < _num; ++i) { // One statement missing here } }