Ok, I'm trying to make a card class that can shuffle a deck of cards so I never have to write this shuffle code again. I have the two files here and attached to this post. I'm gettin some error, it's probably has something to do with my class syntax. It was written in dev c++ 4. In these files, I actually documented a lot (something i rarely do).
heres the header file
//cardclass.h
//makes, and suffles a deck of cards
//including suits, numbers (1-13), and faces
// IMPLEMENTATION IS EXPLAINED At THE END OF THE CPP FILE
#ifndef_CARDCLASSMADEBYTIMSEGANPINKBIGFLOATINGELEP HANTFROMCUBA
#define_CARDCLASSMADEBYTIMSEGANPINKBIGFLOATINGELEP HANTFROMCUBA
#include <apvector.h> //needed for card aray
#include <apstring.h> //needed for faces
#include <stdlib.h> //needed for randomizing
//#include <windows.h> //not sure if it is needed
struct cardtype
{ //TYPE OF DATA USED IN ARRAYS
//USAGE: card[1].suit
int num; //number (1-13)
int suit; //Suit (3-6)
apstring face; //1...9, q, a, (10 = t)
int val; //card's value (although ace is tricky)
};
class cardclass
{
public:
cardclass();
//there really isnt a need for any public data
void shuffle();
private:
apvector<cardtype>card(53);
int num (int); //returns # of card (1-13)
apstring face (int); //returns face ("A", "10"...)
char csuit (int); //returns char of suit (pic of suit)
int nsuit (int); //returns # of suit (3-6)
};
#include "cardclass.cpp"
#endif
I would REALLY appreciate the fix(es) for my problems here because I am the worst debugger ever.// CARDCLASS.CPP
cardclass::cardclass()
{
apvector<cardtype>card; //dont know if this is necessary
}
void cardclass::shuffle()
{
//ERASING
for (int i = 1; i<=52; i++)
{
card[i].num=0;
card[i].suit=0; //sets all aspects of card to blank
card[i].face="";
card[i].val=0;
}
//SHUFFLING
for (int i = 1; i<=52; i++) //i is simple loop variable
{
RERANDOM:
card[i].num=rand()%13+1; //random card
card[i].suit=rand()%4+3; //random suit
bool uni=true; //uni=unique
if (i!=1) //if its 1, it is unique (first card has to be...)
{
for(int t=1; t<i; t++) //check loop
{
if (card[i].suit==card[t].suit && card[i].num==card[t].num) //if cards are the same
bool uni=false;
}
}
if (uni==false) //if card isnt unique
goto RERANDOM; //rerandomize the card
}
}
int cardclass::num(int i)
{
return card[i].num; //RETURNING NUM (1-13)
}
apstring cardclass::face(int i)
{
return card[i].face; //RETURNING FACE
}
char csuit (int i)
{
return char(card[i].suit); //returning character value of suit
}
int nsuit (int i)
{
return card[i].suit; //RETURNING SUIT # (1-6)
}
/*GET THE SUIT TO WORK BY
#include "cardclass.h"
...
cardclass card();
card.suffle();
cout<<card.num(5);
WOULD PRINT OUT # OF CARD ON SCREEN
*/