final review

The flashcards below were created by user dimeng on FreezingBlue Flashcards.

  1. You are given a template sorting function. You use it to sort an array of ints and an array of doubles, but it wont compile when you give it an array of Jedi. Why won't it work?
    Because Jedi are objects, the compiler does not know when one Jedi is greater than or less than another unless the Jedi class contains overloaded greater than and less than (comparison) operators.
  2. (T/F) A recursive function cannot ever call any function other than itself.
    False
  3. (T/F) If a recursive function's base case is never met, the function will recurse infinitely.
    False, the system will run out of memory causeing a stack overflow error.
  4. A ________ variable will stay in memory even after the function that declared it is removed from the stack.
    static
  5. When deleting from a standard linked list, removing the ________ must be treated as a special case.
    head - because without the head the entire list is inaccessible
  6. List the 4 questions that verify that a problem can be solved recursively.
    • (Remember SBCR - smaller, base case, closer, reduce)
    • 1) Can you define the problem in terms of smaller versions of itself?
    • 2) What is/are the base case(s) - when the problem is solved?
    • 3) Will each step (recursive call) move you closer to the solution?
    • 4) Are you guaranteed to reach a base case?
  7. Which linked list variant contains no null pointers (unless it's empty)?
    a) Circular
    b) Doubly linked
    c) Dummy head node
    d) Queue
    Circular
  8. Why can't a linked list directly access any of its nodes?
    A linked list node can only be accessed using the pointer to it that is stored in the previous node.
  9. What would you have to do to an array to make it work like a Stack?
    • You would keep track of the index of the top element (the largest index of an element in the array).
    • When an element is added to the stack it must be added to the top + 1 index of the array.
    • When an element is removed from the stack the element at the top position of the array must be deleted.
  10. What would you have to do to a Linked List to make it work like a Queue?
    • You should implement a Linked list with a tail pointer because insertions in a Queue happen at the end, while deletions happen at the head.
    • When you add an item to this queue, you must update the tail pointer and update the previous tail's next to point to the new node.
    • When you delete an item from this queue, you use a pointer (curr) to point to the old head, advance head to head-> next, and delete curr.
  11. What do you have to do when enqueueing and dequeueing an in array-based queue to "wrap-around"?
    ******************Look this up *************************
  12. You have a list of numbers that is almost entirely sorted smallest to largest. Only one small-value number is out of place and it is near the end of the list amongst the large numbers. Why would insertion sort outperform bubble sort in this situation?
    Bubble sort can only move items toward the beginning of the list one position for each iteration of the sort algorithm. Insertion sort will move the small-value number to its proper position in the iteration that positions the small-value number into the sorted portion of the list.
  13. If a sequential search is performed on an array, how many items would have to be looked at to find the n-th item in the list?
    n items. 1st = 1 look, 2nd = 2 looks, ...
  14. If a binary search is performed on an array, how many items would have to be looked at to find the n-th item on the list?
    It depends on the position. Since binary search splits the "list" in half each iteration, it depends on the size of the list.
  15. If you const modify a member function in a class, what is the result?
    a) You cannot call the function
    b) The function can access and change an object's data
    c) The function can access an object's data, but cannot change it.
    d) The function cannot access an object's data.
    c
  16. Class definitions always end with:
    a) }
    b) };
    c) );
    d) }}
    b
  17. If you use the static modifier on a local variable in a function, what is the result?
    a) The function cannot modify the variable.
    b) The variable stays in memory after the function ends.
    c) Once you set the variable's value, you cannot change it.
    d) All functions in the program can change the variable.
    b
  18. Select the default constructor:
    a) Zip (const Zip &zip);
    b) Hype h;
    c) Bowler (string name, int score);
    d) Crayon();
    d
  19. Select the initializing constructor:
    a) Bowler(string name, int score);
    b) Zip(const Zip &z);
    c) Hype h;
    d) Crayon();
    a
  20. Select the copy constructor:
    a) Zip(const Zip &z);
    b) Hype h;
    c) Bowler(string name, int score);
    d) Crayon();
    a
  21. One of these sentences is false, select it.
    a) By default, all functions in C++ are const.
    b) By default, all functions in C++ are global.
    c) Member functions in a class should be in the public: section of the class definition.
    d) The scope resolution operator(::) marks a function as belonging to the class.
    b
  22. The #pragma once and #ifndef - #define - #endif combo serve the same purpose. What is it?
    They both serve to prevent redefining the class in memory.
  23. Public inheritance is which type of class relationship?
    a) has-a
    b) Was-a
    c) Is-a
    d) As-a
    c
  24. (T/F) In C++, you can derive a class directly from more than one superclass.
    true
  25. (T/F) Composition is the same as protected inheritance.
    false
  26. In C++, what notation is used to indicate that a function is a pure virtual function?
    a) *p
    b) &x
    c) =0
    d) <>
    c
  27. (T/F) Any pointer can be used to create a dynamic array.
    true
  28. List the big three functions that you need to make when a class uses pointers to create dynamic memory.
    • overloaded assignment operator
    • copy constructor
    • destructor
  29. When does a class's copy constructor execute?
    a) When a new object is being created as a call-by-reference parameter.
    b) When a new object is being created using an initializing constructor.
    c) When a new object is being created as a call-by-value parameter.
    d) When the object is going out of scope.
    c
  30. What are friend functions?
    a) Non-member functions that have access to member data.
    b) Non-member functions that have access to non-member data.
    c) Member functions that have access to member data.
    d) Member functions that have access to non-member data.
    a
  31. The two overloaded operators shown below can be called using (obj + obj2). Indicate which one is a member function of class Goober and which one is not.
    bool operator < (Goober g1, Goober g2);
    bool operator < (Goober g1);
    The first is a non-member; you can tell because it has two arguments. The second is a member because it has one argument.
  32. To prevent a pointer from 'dangling', set its value to ________.
    NULL
  33. You are given a template sorting function. You use it to sort an array of ints and also an array of doubles, but it won't compile when you give it an array of Jedi. Why won't it work?
    A sorting function must be able to compare two objects and determine which is greater (or if they are equal.) Because the Jedi function did not contain an overloaded comparison operator (> or <), the sorting function would not work.
  34. (T/F) A recursive function cannot ever call any function other than itself.
    False
  35. (T/F) If a recursive function's base case is never met, the function will recurse infinitely.
    False - you will run out of memory (stack overflow)
  36. A ________ variable will stay in memory even after the function that declared it is removed from the stack.
    static
  37. When deleting from a standard linked list, removing the ________ must be treated as a special case.
    a) Head
    b) Tail
    c) both a and b
    d) Neither a nor b
    a
  38. List the 4 questions that verify that a problem can be solved recursively.
    • 1) Can you define the problem in terms of smaller identically structured versions of itself?
    • 2) What is/are the base case(s) - when the problem is solved?
    • 3) Will each step (recursive call) move you closer to the solution?
    • 4) Are you guaranteed to reach a base case?
    • (Mnemonic - sbcr - smaller base case closer reach)
  39. Which linked list variant contains no null pointers (unless it's empty)?
    a) circular
    b) doubly linked
    c) dummy head node
    d) queue
    a
  40. Why can't a linked list directly access any given one of its nodes?
    A linked list can only access a node from the previous node in the list (which holds a pointer to the desired node).
Author:
dimeng
ID:
313091
Card Set:
final review
Updated:
2015-12-12 02:35:15
Tags:
diane cs240
Folders:
diane,cs240
Description:
c++ final exam review
Show Answers: