Don't worry about the const thingy yet then. You can easely remove it. It is to prevent changing data that doesn't need to be changed.
This pair thingy is my view on what a single card is. To me a card is typically recognized by two properties: its suit and its value.
A suit is nothing else but a name: hearts, spades, clubs, diamonds. And the values are usually 1/11, 2, 3, .... 10. But anyways, typically a card is recognized by the pair suit/value. This is ideal for a container provided by the C++ STL. See the code below for a demonstration on how to create a single card:
Code:
#include <iostream>
#include <utility> //pair
#include <string>
using namespace std;
int main()
{
pair<string, unsigned> theCard("Hearts", 2);
cout << theCard.first << endl;
cout << theCard.second << endl;
return 0;
}
Let's see if I can make 52 cards and dump them all in a nice vector. The whole idea is to load the vector with 52 objects of type "pair". But each object has a different suit/value combination obviously.
Code:
#include <iostream>
#include <utility> //pair
#include <string>
#include <vector>
using namespace std;
int main()
{
//STEP 1: A card is a pair or suit/value properties.
pair<string, unsigned> theCard;
//STEP 2: A deck is a container that holds suit/value properties.
vector<pair<string, unsigned> > theDeck;
//STEP 3: A nice way to load a deck with 52 cards:
unsigned cardtype;
string suit;
for (unsigned i=0; i<52; i++)
{
// First 13 cards are Clubs, next 13 are Spades etc.
cardtype = i/13;
switch(cardtype)
{
case 0: suit = "Club"; break;
case 1: suit = "Spade"; break;
case 2: suit = "Diamond"; break;
case 3: suit = "Heart"; break;
}
//STEP 4: So this is the card. Change the the pair object to its current card.
theCard.first = suit;
theCard.second = 2+i%13;
//STEP 5: And then add this object to the vector.
theDeck.push_back(theCard);
}
//We're done. We have a vector with 52 cards. Let's verify that.
for (unsigned i=0; i<52; i++)
{
cout << theDeck[i].first << " " << theDeck[i].second << endl;
}
//In this example the Jack, Queen and the King have values from 12, 13 and 14.
//But you can obviously customize this in STEP 3. For example, all pictures may
//need to have the same value. In black jack that is 10.
//Just think of a clever trick.
//And if you need to have two jokers in the deck, then you'll need to find
//another "clever" trick. Yada yada yada :)
return 0;
}
No worries if you don't have the time to finish your project. But I think you should play with the code I gave you. There's a lot of room to experiment with. That's what I always used to do when I was a student. I grabbed code from more experianced programmers and fiddled with it on a lazy sunday. I stared at it for an hour until I finally could "see" what was going on

.