Deck of Cards OOP

Hi, I'm working on my first OOP project and the goal is to make a deck of cards, shuffle the cards and then rank the first five cards based off of general poker hand hierarchy although I'm not too concerned about the ranking at this point. I just want to get my cards to print haha.

Here are the official project guidelines:

Create a standard deck of 52 playing cards and list those cards on the screen.
"Shuffle" the deck and list the shuffled deck on the screen. random_shuffle from <algorithm> will work on a vector of Cards.

Then evaluate the first 5 cards of the deck fora pair (say the card rank, like Pair of Queens)
two pair (say something like Pair of Queens and Pair of Twos)
three of a kind (say something like Three Kings)
full house (say something like Full house, Jacks over fours)
etc.

This is what I have came up with so far:

main:
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
#include <iostream>
#include <vector>
#include <algorithm>
#include "card.h"

using namespace std;


int main()
{
    vector<Card> game;

    Card c;

    char mySuit[] = {'H','D','C','S'};
    char myFace[] = {'2','3','4','5','6','7','8','9','T','J','Q','K','A'};

    for (int i=0; i<13; i++)
    {
        for (int j=0; j<4; j++)
        {
               c.setFace(myFace[i]);
               c.setSuit(mySuit[j]);

            game.push_back(new Card(myFace[i],mySuit[j]));

        }
    }

     random_shuffle (game.begin(), game.end());




    return 0;
}


card.h:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef CARD_H
#define CARD_H


class Card
{
    Card();
    char mySuit, myFace;
public:

    void listCards();
    void setFace (char data);
    void setSuit (char data);

    char getFace();
    char getSuit();

protected:
private:

};

#endif // CARD_H 


card.cpp
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
#include "card.h"
#include <vector>
#include <algorithm>

using namespace std;

Card::Card()

{
    char mySuit[j];
    char myFace[i];

    for (i=1; i<13; i++)
    {
        for (j=0; j<4; j++)
        {
            c[i][j];
        }
    }

}

void Card::listCards()
{
    vector<Card>::iterator it;
    for (it=game.begin(); it!=game.end(); it++)
    {


    }
}
void Card::setFace (char data)
{
    myFace = data;
}
void Card::setSuit (char data)
{
    mySuit = data;
}
char Card::getFace()
{
    return myFace;
}
char Card::getSuit()
{
    return mySuit;
}


Errors I'm getting are:
card:card() is private line 7 of card.h
error within this context, main.cpp line 13
error no matching function to call card:card(char& , char&)

card:card() is private line 7 of card.h
You've put the default constructor in private space so you can't call it from outside the class. This is bad. Make it public.

Card(myFace[i],mySuit[j]) This constructor does not exist. You can't call functions that don't exist. If it did exist, new would give you back a pointer to a Card, which you are then trying to push_back onto a Vector of Card objects. You can't push_back a pointer-to-Card onto a Vector of Card.
Last edited on
Topic archived. No new replies allowed.