13.12. Multiple Choice ExercisesΒΆ

What is the output of the code below?

enum Month { JAN = 1, FEB, MAR, APR,
MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };

int main() {
  Month m1 = JUL;
  Month m2 = NOV;
  cout << m1 << " " << m2 << endl;
}

What is the output of the code below?

int main() {
  string s = "summer";
  switch (s) {
    case "spring":
      cout << "It's spring!";
      break;
    case "summer":
      cout << "It's summer!";
    case "fall":
      cout << "It's fall!";
      break;
    case "winter":
      cout << "It's winter!";
    default:
      cout << "Invalid season!";
      break;
  }
}

What is the output of the code below?

enum Season { SPRING, SUMMER, FALL, WINTER };

int main() {
  Season s = SUMMER;
  switch (s) {
    case SPRING:
      cout << "It's spring!";
      break;
    case SUMMER:
      cout << "It's summer!";
    case FALL:
      cout << "It's fall!";
      break;
    case WINTER:
      cout << "It's winter!";
    default:
      cout << "Invalid season!";
      break;
  }
}

Take a look at the struct definition of Entry. If we wanted to make a struct called Dictionary, how can we create a vector of Entrys as a member variable?

struct Entry {
  string word;
  int page;
}

What is wrong with the code below?

struct Card {
  int suit, rank;

  Card ();
  Card (int s, int r);

  void print () const;
  bool isGreater (const Card& c2) const;
  int find (const Deck& deck) const;
};

struct Deck {
  vector<Card> cards;

  Deck ();
  Deck (int n);
  void print () const;
  int find (const Card& card) const;
};

Why can't we code our shuffle function to work the exact same way humans shuffle cards?

What is true about helper functions?

Using pseudocode to figure out what helper functions are needed is a characteristic of what?

Which of the following can lead to off by one errors?

What is the amount of time that mergeSort takes?

What kind of sorting algorithm is our sortDeck function? You are encouraged to search up these different sorting algorithms!