CS253: Software Development with C++

Fall 2019

IQ 07

CS253 IQ 07

Show Main.IQ07 as a slide show.

What problem do virtual functions deal with?

  1. Fireball
  2. Invisibility
  3. Polymorphism
  4. Regeneration
  5. Simulacrum

Which of these is correct?

class Base { };
class Derived : public Base { };
Base *b = …;
Derived *d = …;
  1. b = dynamic_cast<Base *>(d);
  2. b = dynamic_cast(Base *, d);
  3. b = dynamic_cast(d);
  4. d = dynamic_cast(b);
  5. d = dynamic_cast<Derived *>(b);
  6. d = dynamic_cast(Derived *, b);

Any problems with this code?

#ifndef FOO_H_INCLUDED

#include "otherfile.h"
#include <string>
class Foo {

};

#define FOO_H_INCLUDED
#endif
  1. It’s fine.
  2. The #ifndef should be #ifdef.
  3. The define is in the wrong place.
  4. It’s unnecessary—include guards are no longer required in modern compilers.

Bit Manipulation

What’s the best way to find out if bit #7 (where bit #0 is the LSB) of the int v is set?

  1. if (v.bit(7))
  2. if (v & 00000080)
  3. if (v && (1 << 7))
  4. if ((v>>7) & 01)
  5. if ((v<<24) < 0)