CS253: Software Development with C++

Spring 2020

IQ 07

CS253 IQ 07

Show Main.IQ07 as a slide show.

Cañon City

How many bytes are needed for the “a” in “Cañon City”?

  1. 0
  2. 1
  3. 2
  4. 3
  5. 4
cout << "a"s.size() << '\n';
1

Cañon City

How many bytes are needed for the “ñ” in “Cañon City”?

  1. 0
  2. 1
  3. 2
  4. 3
  5. 4
cout << "ñ"s.size() << '\n';
2

Cañon City

What will this code display?

string s = "Cañon City";
cout << s[4] << '\n';
o
  1. C
  2. a
  3. ñ
  4. o
  5. n

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.