Advertisement
Guest User

Untitled

a guest
Nov 12th, 2011
998
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. /*
  8.  *
  9.  */
  10.  
  11. /*
  12. a) Data members face and suit of type int.
  13. b) A constructor that receives two ints representing the face and suit and uses them to initialize
  14. the data members.
  15. c) Two static arrays of strings representing the faces and suits.
  16. d) A toString function that returns the Card as a string in the form “face of suit.” You
  17. can use the + operator to concatenate strings. */
  18. class Card
  19. {
  20. public:
  21.    
  22.     Card(int, int);
  23.     string toString();
  24.    
  25. private:
  26.    
  27.     int suit, face;
  28.     static string faceNames[13];
  29.     static string suitNames[4];
  30.    
  31. };
  32.  
  33. string Card::faceNames[13] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Queen","Jack","King"};
  34. string Card::suitNames[4] = {"Diamonds","Clubs","Hearts","Spades"};
  35.  
  36. string Card::toString()
  37. {
  38.     return faceNames[face]+" of "+suitNames[suit];
  39. }
  40.  
  41. Card::Card(int f, int s)
  42. :face(f),
  43.  suit(s)
  44. {
  45.    
  46. }
  47.  
  48.  
  49. /*
  50.  Class DeckOfCards should contain:
  51. a) A vector of Cards named deck to store the Cards.
  52. b) An integer currentCard representing the next card to deal.
  53. c) A default constructor that initializes the Cards in the deck. The constructor should use
  54. vector function push_back to add each Card to the end of the vector after the Card is
  55. created and initialized. This should be done for each of the 52 Cards in the deck.
  56. d) A shuffle function that shuffles the Cards in the deck. The shuffle algorithm should
  57. iterate through the vector of Cards. For each Card, randomly select another Card in the
  58. deck and swap the two Cards.
  59. e) A dealCard function that returns the next Card object from the deck.
  60. f) A moreCards function that returns a bool value indicating whether there are more Cards
  61. to deal.
  62.  */
  63.  
  64. class DeckOfCards
  65. {
  66.    
  67. public:
  68.    
  69.     DeckOfCards();
  70.     void shuffleCards();
  71.     Card dealCard();
  72.     bool moreCards();
  73.    
  74. private:
  75.    
  76.     vector<Card> deck(52);
  77.     int currentCard;
  78.    
  79. };
  80.  
  81. int main(int argc, char** argv) {
  82.  
  83.     return 0;
  84. }
  85.  
  86. DeckOfCards::DeckOfCards()
  87. {
  88.     //I'm stuck here I have no idea of what to take out of here.
  89.     //I still don't fully get the idea of class inside class and that's turning out as a problem.
  90.     for(int i=0; i<deck.size(); i++)
  91.     {
  92.        deck[i]//....
  93.        
  94.     }
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement