{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lec17 - Lecture 17 Vectors PIC 10A Todd Wittman Drawing...

This preview shows pages 1–4. Sign up to view the full content.

1 Lecture 17: Vectors PIC 10A Todd Wittman Drawing Cards ring4 When we talked about random numbers, we mentioned using a switch statement to pick a random card suit. string suit; int suit_number = 1+rand()%4; switch(suit_number) { case 1: suit = "Clubs"; break; case 2: suit = "Diamonds"; break; case 3: suit = "Hearts"; break; case 4: suit = "Spades"; break; } ring4 I’ll let you figure out how to pick a random rank. ring4 Can we use this to make a Card class?

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 The Card Class ring4 We could construct a Card class that stores a playing card. class Card { public: Card( ); .... private: string suit; string rank; }; ring4 It would be cool if a call to our constructor ( Card card1; ) drew a random card. What other member functions should we have? The Card Class ring4 It would be nice if the default constructor for a Card class generated a random card. Card::Card( ) { string suit; int my_rand = 1+rand()%4; switch(my_rand) { case 1: suit = "Clubs"; break; case 2: suit = "Diamonds"; break; case 3: suit = "Hearts"; break; case 4: suit = "Spades"; break; } .... We already have suit as a private variable. Don’t re-declare it!
3 Simulate Drawing Cards ring4 In next week’s HW, you can assume the cards are drawn from more than one deck. ring4 So it’s OK to get card1 = “Queen of Hearts” card2 = “Queen of Hearts” ring4

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

Lec17 - Lecture 17 Vectors PIC 10A Todd Wittman Drawing...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online