Bag  0.91
CardGuesser.cpp
Go to the documentation of this file.
1 // Created by Frank M. Carrano and Tim Henry.
2 // Copyright (c) 2013 __Pearson Education__. All rights reserved.
3 #include <iostream> // For cout and cin
4 #include <string> // For string objects
5 #include "Bag.h" // For ADT bag
6 using namespace std;
7 int main()
8 {
9  string clubs[] = { "Joker", "Ace", "Two", "Three",
10  "Four", "Five", "Six", "Seven",
11  "Eight", "Nine", "Ten", "Jack",
12  "Queen", "King" };
13 
14  // Create our bag to hold cards.
15  Bag<string> grabBag;
16 
17  // Place six cards in the bag.
18  grabBag.add(clubs[1]);
19  grabBag.add(clubs[2]);
20  grabBag.add(clubs[4]);
21  grabBag.add(clubs[8]);
22  grabBag.add(clubs[10]);
23  grabBag.add(clubs[12]);
24 
25  // Get friendÕs guess and check it.
26  int guess = 0;
27  while (!grabBag.isEmpty())
28  {
29  cout << "What is your guess?"
30  << "(1 for Ace to 13 for King):";
31  cin >> guess;
32 
33  // Is card in the bag?
34  if (grabBag.contains(clubs[guess]))
35  {
36  // Good guess Ð remove card from the bag.
37  cout << "You get the card!\n";
38  grabBag.remove(clubs[guess]);
39  }
40  else
41  {
42  cout << "Sorry, card was not in the bag.\n";
43  } // end if
44  } // end while
45 
46  cout << "No more cards in the bag. Game over!\n";
47  return 0;
48 }; // end main