170 likes | 346 Views
CISC181 Introduction to Computer Science Dr. McCoy Lecture 24 Clicker Questions November 24, 2009. Given the class definition class CreateDestroy { public: CreateDestroy() { cout << "constructor called, "; } ~CreateDestroy() { cout << "destructor called, "; } };
E N D
CISC181 Introduction to Computer ScienceDr. McCoyLecture 24Clicker QuestionsNovember 24, 2009
Given the class definition class CreateDestroy { public: CreateDestroy() { cout << "constructor called, "; } ~CreateDestroy() { cout << "destructor called, "; } }; What will the following program output? int main() { CreateDestroy c1; CreateDestroy c2; return 0; }
Given the class definition class CreateDestroy { public: CreateDestroy() { cout << "constructor called, "; } ~CreateDestroy() { cout << "destructor called, "; } }; What will the following program output? int main() { CreateDestroy c1; CreateDestroy c2; return 0; } (a) constructor called, destructor called, constructor called, destructor called. (b) constructor called, destructor called. (c) constructor called, constructor called. (d) constructor called, constructor called, destructor called, destructor called.
The assignment operator (=) can be used to (a) test for equality. (b) copy the data from one object to another. (c) compare two objects. (d) copy a class.
If the line friend class A; appears in class B, and friend class B; appears in class C then (a) class A is a friend of class C. (b) class A can access private variables of class B. (c) class C can call class A’s private member functions. (d) class B can access class A’s private variables.
Linked lists allow (a) insertions and removals anywhere (b) insertions and removals only at one end (c) insertions at the back and removals from the front (d) none of the above
The __________ operator takes as an argument the type of object being allocated and returns a __________. (a) new, pointer to an object of that type (b) new, reference to an object of that type (c) new, copy of the object of that type (d) sizeof, pointer
__________ is not an advantage of linked lists when compared to arrays. (a) Dynamic memory allocation (b) Efficient insertion and deletion (c) Direct access to any list element (d) Efficient use of memory
Which of the following is false about the new operator and the object it allocates memory for? (a) it calls the object’s constructor. (b) it returns a pointer. (c) it does not require size of the object to be specified. (d) it automatically destroys the object after main is exited.
For a non-empty linked list, select the code that should appear in a function that adds a node to the end of the list. newPtr is a pointer to the new node to be added, and lastPtr is a pointer to the current last node.Each node contains a pointer nextPtr, which is a link to a node.
Add a node to the end of the list: (a) lastPtr->nextPtr = newPtr; lastPtr = newPtr; (b) lastPtr = newPtr; lastPtr->nextPtr = newPtr; (c) newPtr->nextPtr = lastPtr; lastPtr = newPtr; (d) lastPtr = newPtr; newPtr->nextPtr = lastPtr;
Given the line delete newPtr; what can you conclude? (a) The memory referenced by newPtr is released only if it is needed by the system. (b) newPtr is of type void *. (c) newPtr only exists if there was an error freeing the memory. (d) newPtr still exists.
A linked list has the functions insertAtFront, removeFromFront, insertAtBack, and removeFromBack, which perform operations on nodes exactly as their names describe. Which two functions would most naturally model the operation of a queue? (a) insertAtBack and removeFromBack. (b) insertAtBack and removeFromFront. (c) insertAtFront and removeFromFront. (d) insertAtFront and removeFromBack.
Which of the following statements will not produce a syntax error? (a) defining a const member function that modifies a data member of an object. (b) invoking a non-const member function on a const object. (c) declaring an object to be const. (d) declaring a constructor const.
The delete operator (a) can terminate the program. (b) can delete an entire array of objects declared using new. (c) must be told which destructor to call when destroying an object. (d) is called implicitly at the end of a program.
The code fragment Increment::Increment(int c, int i) : increment (i) { count = c; } tells you (a) Increment is a const variable. (b) Increment must be a const function. (c) increment may or may not be a destructor. (d) increment may be a const variable.
When composition (one object having another object as a member) is used (a) the host object is constructed first and then the member objects are placed into it (b) member objects are constructed first, in the order they appear in the host constructor’s initializer list (c) member objects are constructed first, in the order they are declared in the host’s class (d) member objects are constructed last, in the order they are declared in the host’s class