Embercode
✕
Object-Oriented ProgrammingQuick quiz

Cleanup and project

8 questions. Covers Inventory mini project.

Questions 1 to 5 of 8

  1. 1. A class Noisy prints open NAME in its constructor and close NAME in its destructor. main runs this block: { Noisy a("a"); Noisy b("b"); std::cout << "end of block\n"; }. Put the printed lines in the order the program prints them.

    Use the arrows to put the steps in order.

    1. 1.open b
    2. 2.end of block
    3. 3.close b
    4. 4.close a
    5. 5.open a
  2. 2. Put these steps in the order they happen when a function creates a local std::lock_guard and then hits an early return.

    Use the arrows to put the steps in order.

    1. 1.The guard's destructor runs and unlocks the mutex
    2. 2.The function creates a local std::lock_guard, and its constructor locks the mutex
    3. 3.A return statement leaves the function's scope early
  3. 3. What does this program print? ``cpp #include <iostream> #include <string> #include <utility> struct Tag { std::string name; explicit Tag(std::string n) : name(std::move(n)) { std::cout << "+" << name; } ~Tag() { std::cout << "-" << name; } }; void f() { Tag a{"a"}; Tag b{"b"}; throw 1; } int main() { try { f(); } catch (int) { std::cout << " caught"; } std::cout << '\n'; } ``
  4. 4. Why does this code fail to compile? ``cpp #include <cstddef> class IntBuffer { public: explicit IntBuffer(std::size_t size) : data_(new int[size]{}) {} ~IntBuffer() { delete[] data_; } IntBuffer(const IntBuffer&) = delete; private: int* data_; }; int main() { IntBuffer a(3); IntBuffer b = a; } ``
  5. 5. The code below compiles, but -Wall prints a warning. What is the cause? ``cpp class Pen { public: Pen(int price, int qty) : qty_{qty}, price_{price} {} private: int price_; int qty_; }; ``

3 question(s) left on this page.