12.12. Multiple Choice ExercisesΒΆ
Select all of the true statements.
What is the correct way to declare a vector of vectors of ints called vec?
What is the value of card?
struct Card {
int suit, rank;
Card ();
Card (int s, int r);
};
Card::Card () {
suit = 0; rank = 0;
}
Card::Card (int s, int r) {
suit = s; rank = r;
}
int main() {
Card card (2, 8);
}
There is an error with the code below. Can you find it?
struct Card {
int suit, rank;
Card ();
Card (int s, int r);
void print () const;
};
int main() {
Card card (1,3);
print (card);
}
What is the output of the code below?
struct Card {
int suit, rank;
Card ();
Card (int s, int r);
void print () const;
bool isGreater (const Card& c2) const;
};
int main() {
Card card1 (2,12);
Card card2 (2,2);
cout << card1.isGreater (card2) << endl;
}
What is the output of the code below?
struct Card {
int suit, rank;
Card ();
Card (int s, int r);
void print () const;
bool isGreater (const Card& c2) const;
};
vector<Card> buildDeck();
bool equals (const Card& c1, const Card& c2){
return (c1.rank == c2.rank && c1.suit == c2.suit);
}
void printDeck(const vector<Card>& deck);
int find (const Card& card, const vector<Card>& deck);
int main() {
vector<Card> deck = buildDeck();
Card card (3, 13);
cout << find(card, deck);
}
What is true about deck?
struct Card {
int suit, rank;
Card ();
Card (int s, int r);
void print () const;
bool isGreater (const Card& c2) const;
};
vector<Card> createDeck() {
vector<Card> deck (12);
int i = 0;
for (int suit = 0; suit <= 3; suit++) {
for (int rank = 1; rank < 4; rank++) {
deck[i].suit = suit;
deck[i].rank = rank;
i++;
}
}
return deck;
}
int main() {
vector<Card> deck = createDeck();
}
How many times does findBisect need to call itself in order to find the King of Diamonds?
struct Card {
int suit, rank;
Card ();
Card (int s, int r);
void print () const;
bool isGreater (const Card& c2) const;
};
vector<Card> buildDeck();
bool equals (const Card& c1, const Card& c2);
void printDeck(const vector<Card>& deck);
int find (const Card& card, const vector<Card>& deck);
int findBisect (const Card& card, const vector<Card>& deck, int low, int high);
int main() {
vector<Card> deck = buildDeck();
Card card (1, 13);
cout << findBisect(card, deck, 0, 51);
}
We want to write the function findAllQueens, which searches through a deck and
prints out the location of all 4 queens in the deck. What should go in the blanks?
struct Card {
int suit, rank;
Card ();
Card (int s, int r);
void print () const;
bool isGreater (const Card& c2) const;
};
vector<Card> buildDeck();
bool equals (const Card& c1, const Card& c2);
void printDeck(const vector<Card>& deck);
void findAllQueens (const vector<Card>& deck) {
for (size_t i = 0; i < deck.____; ++i) {
if (deck[i].____ == 12) {
cout << ____ << " ";
}
}
}
int main() {
vector<Card> deck = buildDeck();
findAllQueens (deck);
}
What is the process of modeling a complex system with a simplified description in order to suppress unnecessary details while capturing relevant behavior?