CS253: Software Development with C++

Fall 2019

IQ 06

CS253 IQ 06

Show Main.IQ06 as a slide show.

is-a

class Unikitty { };
class Puppycorn : public Unikitty {
    int dr_fox;
};

Which of these is true?

  1. Unikitty is-a Puppycorn
  2. Unikitty is-a dr_fox
  3. Puppycorn is-a Unikitty
  4. Puppycorn is-a dr_fox
  5. dr_fox is-a Unikitty
  6. dr_fox is-a Puppycorn

has-a

class Unikitty { };
class Puppycorn : public Unikitty {
    int dr_fox;
};

Which of these is true?

  1. Unikitty has-a Puppycorn
  2. Unikitty has-a dr_fox
  3. Puppycorn has-a Unikitty
  4. Puppycorn has-a dr_fox
  5. dr_fox has-a Unikitty
  6. dr_fox has-a Puppycorn

Inheritance

Can private methods in a derived class call private methods in the base class?

  1. Yes, a derived class has full access to the base class methods.
  2. Yes, if the base class methods are declared as public in the derived class.
  3. No—private!

--

Which method is the best way to make Foo f; f--; work?

  1. operator--()
  2. operator--(int)
  3. Foo operator--()
  4. Foo operator--(int)
  5. Foo &operator--()
  6. Foo &operator--(int)

stringstream

What will this code produce?

ostringstream oss;
oss = "Flying Spaghetti Monster";
cout << oss.str();
c.cc:2: error: no match for 'operator=' in 'oss = "Flying Spaghetti Monster"' 
   (operand types are 'std::ostringstream' {aka 
   'std::__cxx11::basic_ostringstream<char>'} and 'const char [25]')
  1. Flying
  2. Flying Spaghetti Monster
  3. 6
  4. 24
  5. None of the above