C++ Project to Build Shuffle Deck of Cards Poker Game in Command Line

You are currently viewing C++ Project to Build Shuffle Deck of Cards Poker Game in Command Line

C++ Project to Build Shuffle Deck of Cards Poker Game in Command Line

//
//  Card.h
//  chapter18_自动洗发牌
//
//  Created by Moon on 2020/12/5.
//  Copyright © 2020 Moon. All rights reserved.
//
 
#include <string>
using namespace std;
 
#ifndef Card_h
#define Card_h
 
class Card
{
public:
    Card(int face, int suit);
    void setCardFace(int);
    void setCardSuit(int);
    int getCardFace() const;
    int getCardSuit() const;
    string toString() const;
private:
    int face;//1-13
    int suit;//1-4
    
    static string cardFace[13];
    static string cardSuit[4];
};
 
#endif /* Card_h */
//



//  Card.cpp
//  chapter18_自动洗发牌
//
//  Created by Moon on 2020/12/5.
//  Copyright © 2020 Moon. All rights reserved.
//
 
#include <stdio.h>
#include "Card.h"
#include <string>
using namespace std;
 
string Card::cardFace[13] = {"ace" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" , "ten" , "jack" , "queen" , "king"};
string Card::cardSuit[4] = {"heart" , "spade" , "club" , "diamond"};
 
Card::Card(int fa, int su)
{
    setCardFace(fa);
    setCardSuit(su);
}
 
void Card::setCardFace(int fa)
{
    face = fa;
}
void Card::setCardSuit(int su)
{
    suit = su;
}
int Card::getCardFace() const
{
    return face;
}
int Card::getCardSuit() const
{
    return suit;



}
string Card::toString() const
{
    string f = cardFace[getCardFace() - 1];
    string s = cardSuit[getCardSuit() - 1];
    string faceAndSuit = f + " " + "of" + " " + s;
    //return f.append(s);
    return faceAndSuit;
}
//
//  DeckOfCards.h
//  chapter18_自动洗发牌
//
//  Created by Moon on 2020/12/6.
//  Copyright © 2020 Moon. All rights reserved.
//
 
#include <string>
using namespace std;
 
#ifndef DeckOfCards_h
#define DeckOfCards_h
class DeckOfCards
{
    
}
 
#endif /* DeckOfCards_h */
//
//  main.cpp
//  chapter18_自动洗发牌
//
//  Created by Moon on 2020/12/5.
//  Copyright © 2020 Moon. All rights reserved.
//
 
#include <iostream>
#include <string>
#include "Card.h"
using namespace std;
 
 
int main(int argc, const char * argv[]) {
    // insert code here...
    //std::cout << "Hello, World!\n";
    Card card1(3 , 2);
    cout << "Card is : " << card1.toString() << endl;
    //cout << "suit is : " << card1.getCardSuit() << endl;
    return 0;
}

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply