Object Oriented Data Types quiz

Answer each question to see whether you got it right and why. Your answers are saved in this browser.

0 correct · 0 / 42 answered
  1. Q1ADTs and algorithms

    Which statement describes an algorithm?

  2. Q2ADTs and algorithms

    An ADT specifies exactly how its data is stored in memory.

  3. Q3ADTs and algorithms

    Which is an ADT operation?

  4. Q4ADTs and algorithms

    Start with an empty stack and run push(3), push(7), pop(). What value does pop() return?

  5. Q5ADTs and algorithms

    Which structure removes items in first-in, first-out order?

  6. Q6Find the maximum

    What is the final value of maximum?

    int a[] = {3, 1, 6, 4};
    int maximum = a[0];
    for (int i = 1; i < 4; ++i) {
        if (a[i] > maximum)
            maximum = a[i];
    }
    std::cout << maximum;
  7. Q7Programming process

    A program compiles but prints 11 instead of 10. What kind of error is this?

  8. Q8Static vs dynamic memory

    Which expression allocates an int during execution?

  9. Q9Static vs dynamic memory

    The size of int scores[5]; can be changed while the program runs.

  10. Q10Static arrays

    With int a[3] = {7, 4, 9};, what is a[1]?

  11. Q11Static arrays

    What does this print?

    int a[4] = {2, 3, 5, 7};
    std::cout << a[0] + a[3];
  12. Q12Static arrays

    What does this print?

    int a[4] = {5, 8, 3, 1};
    a[2] = a[0] + a[1];
    std::cout << a[2];
  13. Q13Arrays and functions

    Inside int f(const int a[], int n), what does const forbid?

  14. Q14Arrays and functions

    A function receiving int a[] can tell how many elements the caller's array has.

  15. Q152D arrays

    What does this print?

    int a[2][3] = {{1, 2, 3}, {4, 5, 6}};
    std::cout << a[1][0];
  16. Q162D arrays

    Which is a valid parameter for int a[2][3]?

  17. Q17Addresses and pointers

    With int x = 5;, what does &x mean?

  18. Q18Addresses and pointers

    What does this print?

    int a = 4;
    int* p = &a;
    *p = *p + 3;
    std::cout << a;
  19. Q19Addresses and pointers

    In *p = 20; the * means "pointer to".

  20. Q20The heap

    Which memory must eventually be released by you?

  21. Q21The heap

    What does this print?

    int* p = new int(8);
    std::cout << *p;
    delete p;
    p = nullptr;
  22. Q22The heap

    After delete p; (and no reassignment), is std::cout << *p; valid?

  23. Q23The heap

    After moving the cout before delete z, what does this print?

    int* h = new int(9);
    int* z = new int(5);
    *z = *h + *z;
    std::cout << *z;
    delete z;
    delete h;
  24. Q24Dynamic arrays

    Which statement correctly releases int* p = new int[3];?

  25. Q25Dynamic arrays

    Which allocates n integers at runtime?

  26. Q26Dynamic arrays

    What does this print?

    int* a = new int[3]{1, 2, 3};
    int sum = 0;
    for (int i = 0; i < 3; ++i)
        sum += a[i];
    std::cout << sum;
    delete[] a;
  27. Q27Resizing

    Which step must come before delete[] of the old array when resizing?

  28. Q28Resizing

    void extendArray(int* a, int size) (no references) can resize the caller's array and update the caller's pointer.

  29. Q29Resizing

    After int* middle = a + 2; and then a resize that deletes the old block and repoints a, what is *middle?

  30. Q30Resizing

    What does this print?

    int* a = new int[4]{2, 4, 6, 8};
    int* middle = a + 2;
    int* smaller = new int[3];
    for (int i = 0; i < 3; ++i) smaller[i] = a[i];
    delete[] a;
    a = smaller;
    middle = a + 2;
    std::cout << *middle;
    delete[] a;
  31. Q31Resizing

    What is wrong with this loop when copying into int* smaller = new int[3];?

    for (int i = 0; i <= 3; ++i)
        smaller[i] = a[i];
  32. Q32Resizing

    With capacity == 0, what capacity does this give?

    int next = capacity == 0 ? 1 : capacity * 2;
    std::cout << next;
  33. Q33Resizing

    A full array {8, 1, 6} (size 3, capacity 3) is grown with doubling, then 4 is appended. What are the size, capacity and elements?

  34. Q34Classes

    If scores and count in ScoreLog are private, code outside the class can still modify count directly.

  35. Q35Classes

    A ScoreLog has capacity 4 and starts empty. add(6), add(3), add(8), add(5), add(9) are called. How many of these calls return true?

  36. Q36Classes

    The log is [6, 3, 8, 5]. You call removeLast(r) twice, then add(7). What does it hold, and what was the last r before the add?

  37. Q37Classes

    If removeLast(r) is called on an empty ScoreLog, it returns false and r keeps its old value.

  38. Q38Templates

    What does this print?

    Pair<int> p(8, 3);
    p.swapValues();
    std::cout << p.larger();
  39. Q39Templates

    In T larger() const { return first < second ? second : first; }, which is returned when first == second?

  40. Q40Templates

    void swapValues() could be declared const because it only uses member variables.

  41. Q412D arrays

    What does bestRow return? (It keeps the first row on ties and uses strict >.)

    int a[3][3] = {{-2, 4, 1}, {5, -4, 2}, {0, 1, 1}};
    std::cout << bestRow(a, 3);
  42. Q422D arrays

    What does bestRow(a, 0) return, given the sheet's version that starts with best = -1?