title: Card and Deck classes C++
body: <p>I am a very novice programmer and my assignment to create a Card and Deck class is a little bit over my head...I just need a little push in the right direction because I really have no clue what I am doing.</p>
  
  <p>My Card header file:</p>
  
  <pre><code>#ifndef CARD_H
  #define CARD_H
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  using namespace std;
  class Card
  {
  public:
      static const char SPADES = 'S';
      static const char CLUBS = 'C';
      static const char HEARTS = 'H';
      static const char DIAMONDS = 'D';
  
      Card();
      Card(int v, char s);
  
      const string toString();
      const int compareCard(const Card c);
  
  private:
      int value;
      char suit;
  };
  #endif
  </code></pre>
  
  <p>My Card implementation file:</p>
  
  <pre><code>#include "Card.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  Card::Card(int v, char s)
  {
      if (v &lt; 1 || v &gt; 13)
      { 
              cerr &lt;&lt; "Invalid Card value";
      }
      else
      {
          value = v;
      }
  
      if ((s != SPADES) &amp;&amp; (s != HEARTS) &amp;&amp; (s != DIAMONDS) &amp;&amp; (s != CLUBS))
      {
          cerr &lt;&lt; "Invalid Suit name";
      }
      else
      {
          suit = s;
      }
  }
  
  const string Card::toString()
  {
      string str; 
  
      switch (value)
      {   
          case 1: str = "Ace of ";    
              break;
          case 2: str = "Two of ";    
              break;
          case 3: str = "Three of ";  
              break;
          case 4: str = "Four of ";   
              break;
          case 5: str = "Five of ";   
              break;
          case 6: str = "Six of ";    
              break;
          case 7: str = "Seven of ";  
              break;
          case 8: str = "Eight of ";  
              break;
          case 9: str = "Nine of ";   
              break;
          case 10: str = "Ten of ";   
                   break;
          case 11: str = "Jack of ";  
              break;
          case 12: str = "Queen of ";
              break;
          case 13: str = "King of ";  
              break;
          default: cerr &lt;&lt; "Invalid Card value";
      }//switch
  
      switch (suit) 
      {   
          case SPADES: str += "Spades";   
              break;
          case HEARTS: str += "Hearts";
              break;
          case DIAMONDS: str += "Diamonds"; 
              break;
          case CLUBS: str += "Clubs"; 
              break;
          default: cerr &lt;&lt; "Invalid Card suit";
      }//switch
  
      return str; 
  }
  
  const int Card::compareCard(const Card c) 
  {
       int result;
  
       if (value == c.value)
       {
           result = 0;
       }
       else if (value == 1)
       {
           result = 1;
       }
       else if (c.value == 1)
       {
           result = -1;
       }
       else if (value &lt; c.value)
       {
           result = 1;
       }
       else
       {
           result = -1;
       }
  
       return result;
  }//compareCard
  </code></pre>
  
  <p>My Deck header file:</p>
  
  <pre><code>#ifndef DECK_H
  #define DECK_H
  #include "Card.h"
  #include &lt;string&gt;
  using namespace std;
  class Deck
  {
  public:
      Deck();
      Deck(int num);
  
      void addCard(Card c);
      Card getTopCard();
      Card peekTopCard();
  
      int getNumCards();
      bool isEmpty();
  
      void shuffleDeck(int list[], int size);
      void cutDeck();
  
  private:
      static const int MAX = 52;
      static const int NUM_SUITS = 4;
      static const int NUM_VALUES = 13;
      int numCards;
      Card myCard[MAX];
  
  };
  #endif
  </code></pre>
  
  <p>My Deck implementation file:</p>
  
  <pre><code>#include "Deck.h"
  #include "Card.h"
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  Deck::Deck()
  {
      char suits[4] = {Card::SPADES, Card::HEARTS, Card::DIAMONDS,   Card::CLUBS};
      int count = 0;  
  
      for (int s = 0; s &lt; 4; s++) 
      {
          for (int v = 1; v &lt;= 13; v++)
          {
              myCard[count] = Card(v, suits[s]); 
              count++;
          }           
      }//for
      int numCards = 0;
  }//Deck
  
  Deck::Deck(int num)
  {
      char suits[4] = {Card::SPADES, Card::HEARTS, Card::DIAMONDS, Card::CLUBS};
      int count = 0;
  
      for (int s = 0; s &lt; NUM_SUITS; s++) 
      {
          for (int v = 1; v &lt;= NUM_VALUES; v++)
          {
              myCard[count] = Card(v, suits[s]);
              count++;
          }           
      }//for
  
      if ((num &lt; 0) || (num &gt; MAX))
      {
          cerr &lt;&lt; "Invalid number of cards in the deck";
      }
      numCards = num;
  }//Deck
  
  
  
  void Deck::addCard(Card c)
  {   
      if(numCards == MAX)
      {
          cerr &lt;&lt; "Attempt to add to full deck";
      }//if
      else
      {
          myCard[numCards] = c;
          numCards++;
      }//else
  }//addCard
  
  Card Deck::getTopCard()
  {
      Card c;
  
      if (numCards &gt; 0) 
      {   
          c = myCard[0];  
          for (int i = 1; i &lt; numCards; i++) 
          {
              myCard[i - 1] = myCard[i];
          }
      numCards--; 
      } 
      else 
      {
          cerr&lt;&lt;"Cannot add card from an empty deck.";
      }
      return c;   
  }//getTopCard
  
  Card Deck::peekTopCard()
  {
      Card c;     
  
      if (numCards &gt; 0)
      {   
          c = myCard[0];
      } 
      else 
      {
          cerr&lt;&lt;"Cannot add card from an empty deck.";
      }
      return c;
  }//peekTopCard
  
  int Deck::getNumCards()
  {
      return numCards;
  }//getNumCards
  
  bool Deck::isEmpty()
  {
      bool empty = true;
      if (numCards == 0)
      {
          empty = true;
      }
      else
      {
          empty = false;
      }
  
      return empty;
  }//isEmpty
  
  void Deck:: shuffleDeck(int list[], int size)
  {
      srand(time(0));
      for(int i = 0; i &lt; size; i++)
      {
          int index = rand() % MAX;
          int temp = list[i];
          list[i] = list[index];
          list[index] = temp;
      }//for
  }//shuffleDeck
  </code></pre>