I am trying to create card game, that shuffles the cads in deck
Draws hands and sorts........I am really struck here.....I get all compile errors with Vector<>
Any help would be rally great.
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <vector>
- #include <string>
- #include <rando.h>
- class CardHand {
- public:
- CardHand(int initMaxCards);
- void AddCard(Card theCard);
- void SwapCards(int cardNum1,int cardNum2);
- private:
- vector <Card> theCards;
- int numCards;
- int maxCards; };
- class Card {
- public:
- Card();
- void Assign(char r, char s);
- private:
- char rank;
- char suit;
- };
- class DeckOfCards {
- public:
- DeckOfCards();
- void Shuffle();
- Card DrawFromTop();
- bool IsEmpty();
- private:
- vector<Card> cards;
- int numCards;
- };
- CardHand::CardHand(int initMaxCards):theCards(initMaxCards)
- {
- maxCards = initMaxCards;
- numCards = 0;
- }
- void CardHand::SwapCards(int cardNum1, int cardNum2)
- {
- if (((cardNum1 > 0) && (cardNum1 <= numCards)) &&
- ((cardNum2 > 0) && (cardNum2 <= numCards)))
- {
- Card temp;
- temp = theCards[cardNum1 - 1];
- theCards[cardNum1 - 1] = theCards[cardNum2 - 1];
- theCards[cardNum2 - 1] = temp;
- }
- }
- Card::Card()
- {
- rank = '?';
- suit = '?';
- }
- void Card::Assign(char newRank, char newSuit)
- {
- rank = newRank;
- suit = newSuit;
- }
- /////////////////////////////////////////////////////////////
- DeckOfCards::DeckOfCards():cards(52)
- {
- numCards = 0;
- string suits = "SCHD";
- string ranks = "23456789TJQKA";
- int suitNum, rankNum;
- for (suitNum = 0; suitNum < suits.length(); suitNum++) {
- for (rankNum = 0; rankNum < ranks.length(); rankNum++) {
- cards[numCards].Assign(ranks[rankNum], suits[suitNum]);
- numCards++;
- }
- }
- }
- void DeckOfCards::Shuffle()
- {
- RandGen rando;
- for (int i = 0; i < numCards; i++) {
- int randPos = rando.RandInt(i,numCards-1);
- Card temp = cards[i];
- cards[i] = cards[randPos];
- cards[randPos] = temp;
- }
- }
- Card DeckOfCards::DrawFromTop()
- {
- numCards--;
- return cards[numCards];
- }
- bool DeckOfCards::IsEmpty()
- {
- return (numCards == 0);
- }
- void main(){
- DeckOfCards():cards(52) d1;
- d1.Shuffle();
- cout << "cards shuffled"<< endl;
- }