fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. /*
  7.  *
  8.  */
  9.  
  10. /*
  11. a) Data members face and suit of type int.
  12. b) A constructor that receives two ints representing the face and suit and uses them to initialize
  13. the data members.
  14. c) Two static arrays of strings representing the faces and suits.
  15. d) A toString function that returns the Card as a string in the form “face of suit.” You
  16. can use the + operator to concatenate strings. */
  17. class Card
  18. {
  19. public:
  20.  
  21. Card(int, int);
  22. string toString();
  23.  
  24. private:
  25.  
  26. int suit, face;
  27. static string faceNames[13];
  28. static string suitNames[4];
  29.  
  30. };
  31.  
  32. string Card::faceNames[13] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Queen","Jack","King"};
  33. string Card::suitNames[4] = {"Diamonds","Clubs","Hearts","Spades"};
  34.  
  35. string Card::toString()
  36. {
  37. return faceNames[face]+" of "+suitNames[suit];
  38. }
  39.  
  40. Card::Card(int f, int s)
  41. :face(f),
  42. suit(s)
  43. {
  44.  
  45. }
  46.  
  47.  
  48. /*
  49.  Class DeckOfCards should contain:
  50. a) A vector of Cards named deck to store the Cards.
  51. b) An integer currentCard representing the next card to deal.
  52. c) A default constructor that initializes the Cards in the deck. The constructor should use
  53. vector function push_back to add each Card to the end of the vector after the Card is
  54. created and initialized. This should be done for each of the 52 Cards in the deck.
  55. d) A shuffle function that shuffles the Cards in the deck. The shuffle algorithm should
  56. iterate through the vector of Cards. For each Card, randomly select another Card in the
  57. deck and swap the two Cards.
  58. e) A dealCard function that returns the next Card object from the deck.
  59. f) A moreCards function that returns a bool value indicating whether there are more Cards
  60. to deal.
  61.  */
  62.  
  63. class DeckOfCards
  64. {
  65.  
  66. public:
  67.  
  68. DeckOfCards();
  69. void shuffleCards();
  70. Card dealCard();
  71. bool moreCards();
  72.  
  73. private:
  74.  
  75. vector<Card> deck(52);
  76. int currentCard;
  77.  
  78. };
  79.  
  80. int main(int argc, char** argv) {
  81.  
  82. return 0;
  83. }
  84.  
  85. DeckOfCards::DeckOfCards()
  86. {
  87. //I'm stuck here I have no idea of what to take out of here.
  88. //I still don't fully get the idea of class inside class and that's turning out as a problem.
  89. for(int i=0; i<deck.size(); i++)
  90. {
  91. deck[i]//....
  92.  
  93. }
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘Card::Card(int, int)’:
prog.cpp:26:15: warning: ‘Card::face’ will be initialized after [-Wreorder]
     int suit, face;
               ^
prog.cpp:26:9: warning:   ‘int Card::suit’ [-Wreorder]
     int suit, face;
         ^
prog.cpp:40:1: warning:   when initialized here [-Wreorder]
 Card::Card(int f, int s)
 ^
prog.cpp: At global scope:
prog.cpp:75:23: error: expected identifier before numeric constant
     vector<Card> deck(52);
                       ^
prog.cpp:75:23: error: expected ‘,’ or ‘...’ before numeric constant
prog.cpp: In constructor ‘DeckOfCards::DeckOfCards()’:
prog.cpp:89:24: error: ‘((DeckOfCards*)this)->DeckOfCards::deck’ does not have class type
     for(int i=0; i<deck.size(); i++)
                        ^
prog.cpp:91:14: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
        deck[i]//....
              ^
prog.cpp:93:5: error: expected ‘;’ before ‘}’ token
     }
     ^
stdout
Standard output is empty