1 / 17

CISC181 Introduction to Computer Science Dr. McCoy Lecture 24 Clicker Questions November 24, 2009

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, "; } };

garin
Télécharger la présentation

CISC181 Introduction to Computer Science Dr. McCoy Lecture 24 Clicker Questions November 24, 2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CISC181 Introduction to Computer ScienceDr. McCoyLecture 24Clicker QuestionsNovember 24, 2009

  2. 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; }

  3. 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.

  4. 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.

  5. 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.

  6. 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

  7. 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

  8. __________ 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

  9. 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.

  10. 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.

  11. 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;

  12. 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.

  13. 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.

  14. 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.

  15. 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.

  16. 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.

  17. 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

More Related