1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include "stdafx.h" // Comment out if not Visual Studio
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <algorithm>
using namespace std;
string SUIT[] = { "Heart", "Club", "Spade", "Diamond" }; // <===== CHANGED TO strings
string VALUE[] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
//=====================================================================
class Card
{
public:
Card() {}
Card( int s, int v ) { suit = s; value = v; } // <===== Changed to int
~Card() {}
void printCard(); // <===== WARNING: Not yet set
int cardValue(string); // <===== WARNING: Not yet set
friend ostream &operator<< ( ostream &os, const Card &c ); // <===== Needed to access private members suit and value
private:
int suit; // <===== Changed to int
int value;
string Outputcharacter;
};
ostream &operator<< ( ostream &os, const Card &c ) // <===== THIS IS WHAT gunnerfunner AND AbstractionAnon ARE REPEATEDLY TELLING YOU
{ // OPERATOR << NEEDS OVERLOADING FOR A Card, NOT A Deck *****
os << "Suit: " << SUIT[c.suit] << " Value: " << VALUE[c.value] << '\n';
return os;
}
//=====================================================================
class Deck
{
public:
Deck() {}
~Deck() {}
void fillWholeDeck();
void shufflecard() { random_shuffle( mDeck.begin(), mDeck.end() ); }
Card gettopcard() { return mDeck[0]; } // <===== NOTE THAT THIS IS RETURNING A ***** Card *****
private:
vector <Card> mDeck;
};
void Deck::fillWholeDeck()
{
for (int s = 0; s < 4; s++) // CHECK LOOP LIMIT
{
for (int v = 0; v < 13; v++) // DITTO
{
Card myCard( s, v );
mDeck.push_back( myCard );
}
}
}
//=====================================================================
int main()
{
Deck a;
a.fillWholeDeck();
srand( time(0) );
a.shufflecard();
cout << a.gettopcard() << endl;
}
|