联系我们 - 广告服务 - 联系电话:
您的当前位置: > 关注 > > 正文

世界实时:C++扑克牌类的设计 C++扑克牌类怎么设计?

来源:CSDN 时间:2022-12-21 19:03:50


(资料图片仅供参考)

C++扑克牌

1、设计扑克类Card:主要属性有花色和点数;主要方法有初始化、输出、比较大小等 2、设计一副扑克牌类Cards:主要属性包括扑克对象数组;主要方法有初始化、洗牌、输出等。 3、编写测试程序。

#include#include#include#include#include#includeusing namespace std;class Card{public:string color;string point;Card(string color, string point);Card(string point);void display();void battle(Card card1);};class Cards{public:        vectorcard;        Cards();void display_all();        void shufflePoker();};Card::Card(string color, string point){this->color = color;    this->point = point;}Card::Card(string point){this->color = "";    this->point = point;}void Card::display(){string s = this->color + this->point;    cout<<Spoint])coutpointcolor])coutpoint<<ENDL;ELSE color])coutpoint<<ENDL;ELSECOUTpoint<<endl;}}cards::cards(){string colors[]={"黑心", "红心", "草花", "方块"};    string numbers[]={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};    for(int i=0;i<4;i++)    {for(int j=0;j<13;j++) this-="">card.push_back(Card(colors[i], numbers[j]));        }    }    this->card.push_back(Card("", "大王"));    this->card.push_back(Card("", "小王"));}void Cards::shufflePoker(){srand((unsigned int)time(0));random_shuffle(this->card.begin(), this->card.end());}void Cards::display_all(){for(int i=0;i<CARD.SIZE();I++) --="" {cout<card[i].color;cout<card[i].point + "\t";    }    cout<cout<<"初始化扑克牌:"<

运行结果

责任编辑:

标签:

相关推荐:

精彩放送:

新闻聚焦
Top