(八)Card

#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <random>
#include <string>

using namespace std;

const string Rank[13] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; //撲克牌點數(shù)
const string Suits[4] = {"SPADES","HEARTS","DIAMONDS","CLUBS"}; //撲克牌花色

class Card
{
    private:
        int rank;
        int suit;
    
    public:
        Card(){}
        ~Card(){}
        Card(int rank,int suit)
        {
            this->rank = rank;   //(1)
            this->suit = suit;   //(2)
        }

        int getRank()
        {
            return rank;
        }

        int getSuit()
        {
            return suit;
        }

        void printCard()
        {
            cout << "(" << Rank[rank] << " , " << Suits[suit] << ")";
        }
};

class DeckOfCards
{
    private:
        Card deck[52];

    public:
        DeckOfCards()    //初始化牌桌并進行洗牌
        {
            for(int i = 0; i < 52; i++)
            {
                deck[i] = Card(i%13, i%4);  //(3)
            }

            // srand((unsigned)time(0));                  //設(shè)置隨機種子
            std::random_device rd;
            shuffle(&deck[0], &deck[51],std::default_random_engine(rd()));  //洗牌
        }

        ~DeckOfCards()
        {

        }

        void printCards()
        {
            for(int i = 0; i < 52 ; i++)
            {
                deck[i].printCard();   //(4)
                if((i + 1) % 4 == 0)  cout << endl;
                else cout << "\t";

            }
        }
};

int main()
{
    DeckOfCards* d = new DeckOfCards();  //(5)
    d->printCards();  //(6)

    delete d;
    return 0;
}

答案:
(1) this->

(2) this->

(3) deck[i]

(4) deck[i].

(5) new DeckOfCards()

(6) d->printCards()

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容