You are using a version without Ads of this website. Please, consider donating:

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:
 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include #include #include #include "card.h" using namespace std; int main() { vector 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:

 ``1234567891011121314151617181920212223`` ``````#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
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647`` ``````#include "card.h" #include #include 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::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.