ImageVerifierCode 换一换
格式:DOC , 页数:12 ,大小:70KB ,
资源ID:6982801      下载积分:10 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.docduoduo.com/d-6982801.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录   微博登录 

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(扑克牌游戏编程.doc)为本站会员(yjrm16270)主动上传,道客多多仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知道客多多(发送邮件至docduoduo@163.com或直接QQ联系客服),我们立即给予删除!

扑克牌游戏编程.doc

1、/*第 1 题 扑克牌游戏-源代码及关键源代码注解如下:*/* This Program was written entirely by the author Frank Vokoun. /*preprocessor directives*/#include #include #include #include #include #include / used to seed the random number generator/*class Playing_Card /扑克类private:int m_Value;char m_Face3; /扑克的数字大小char m_Suit ; /扑

2、克的花色(黑、红、梅、方)public:Playing_Card(); / CONSTRUCTORvoid showcard(); / Displays an object of class Playing_Cardvoid Card_Make(int);class Deck /一副扑克(52 张)private:Playing_Card m_cardarray52; / Object array of class Playing_Cardint m_lastdelt;public:Deck(); / CONSTRUCTOR initializes empty Deck objectvoid

3、MakeDeck() ; / makes a complete object of class Deckvoid Deal_One(); / Deals a card from top of the deckvoid ShowDeck(); / Displays a Deck object to the screenvoid DeckShuff(int); / “Shuffles“ a Deck object for int timesvoid Remove_Card(); / Removes used card from Deck Prevents ; / mistakenly using

4、a nonexistant card/ can bu used to send a card ?/*prototypes* void Program_Init(); / Program informationint main();void Center_Text(char ); / Centers textint get_number(); / Gets a integer from userchar Get_Key(); / Gets a char from user, pauses programvoid DeckMakeDriver(); / Tests Several Function

5、s including Makedeckint getRandInt(int min, int max); / Random number generatorvoid prog_close(); / pauses before program termination/*Main*int main()/*/* int main: Main Function Calls other functions/*/* expects: None./* Returns: Integer 0;/* Side effects None/*/* Tasks (1) Seeds the Random number

6、generator/* (2) Calls Program Init function for Title etc./* (3) Call DeckMakeDriver to Test MakeDeck and DeckShuff./*/*srand( (unsigned)time( NULL ) ); / Seeds GetRandIntint Card_Number = 0;Program_Init(); / Showd title etc.DeckMakeDriver(); / The Main Function Driver Tests Deck and/ Playing_Card c

7、lassesprog_close(); / pauses screen outputreturn 1;Playing_Card:Playing_Card() / CONSTRUCTOR/*/* Playing_Card Playing_Card CONSTRUCTOR FOR CLASS Playing_Card/*/* expects: None./* Returns: None/* Side effects None/*/* Tasks Constructs object of class playing_card replaces default constructor/*/ Const

8、ructor replaces default constructorint i;for(i=1;i key to Continue“);cin.get();char Get_Key()/*/* char Get_Key(): Uses a input prompt to get a char/* /* expects: None./* Returns: Input char./* Side effects: Pauses Program execution (desired effect)./*/* Task(s): Gets a char from the user/*/*char x;x

9、 = cin.get();cout Uses calling members Playing_Card object /* Returns: None /* Side Effects: Displays /* /* Task(s): Displays the object of class Playing_Card to screen/* /*cout Input_Integer;return Input_Integer;void Playing_Card:Card_Make(int num)/*/* Get_Card(int): Creates a Playing_Card object b

10、ased on an interger input./* Expects: int /* Returns: None - uses Calling members Playing_Card object/* Side Effects: None/* /*Tasks: 1. assign a face value/* 2. assign a m_Suit(char type)/* 3. assign a point value/*/*int i = 0;char j;int face_num = num % 13; switch(face_num) / Assigns a Face value

11、for string cardscase 0: strcpy(m_Face,“ A“);break;case 9: strcpy(m_Face,“10“);break;case 10: strcpy(m_Face,“ J“);break;case 11: strcpy(m_Face,“ Q“);break;case 12: strcpy(m_Face,“ K“);break;default:j = char(face_num + 49); / Fills string with number mod 13if(i12 void DeckMakeDriver() /*/* DeckMakeDri

12、ver(): Used to test the various deck functions Deckmake,/* Deckshuff, Deckcopy etc./* Expects: None./* Returns: None./* Side effects: None /*/* Tasks: 1. Call make Deck /* 2. Show Deck /* 3. Call shuffle /* 4. Call show deck /* 5. While !Done Call /* a. Deal one /* b. Show card /*/*Note the dot oper

13、ator is need to access object because this is not a member of the class/*Deck deck_1;deck_1.MakeDeck(); / Creates the Deck.deck_1.ShowDeck(); / Displays deck to screen.Get_Key(); / Pauses Program.deck_1.DeckShuff(250); / Shuffles the deck 250 timesdeck_1.ShowDeck(); / Displays deck to screen.cout y;

14、y = toupper(y);while(y = Y );void Deck:MakeDeck() / creates a full deck not a construct/* /* Deck Make Deck(): Creates a Deck Object /* Expects: none - uses calling functions deck object/* Returns: none - uses calling functions Deck object /* Side effects: none /* Tasks: 1. Create a Full Deck struct

15、ure of unique card structures/* a. have the decks last delt variable = to the top card/*m_lastdelt = 51; / Set Deck to emptywhile(m_lastdelt -1) / iterate until deck is full. m_cardarraym_lastdelt.Card_Make(m_lastdelt); / call card make for every card objectm_lastdelt-; / inside the deck object ie c

16、ardarrayvoid Deck:ShowDeck() /* /* void ShowDeck: Displays the deck in a organized readable fashion to the screen/* Expects: none shows calling functions object of class deck /* Returns: none/* Side Effects: None /* Tasks: 1. set an index to lastdealt + 1 /* 2. call ShowCard passing in cardindex /*i

17、nt index = m_lastdelt + 1;int newline = 0;Center_Text(“Current Deck of Cards from top to bottom“);cout uses calling functions Deck object/* Returns: none - manipulates calling functions object of class Deck USING/* A THIS POINTER/* Side effects: no unintended effects./*/* Task(s) 1. To randomly arra

18、nge the elements of the Deck structure Playing_Card/* array./* A. split the Deck structure into two halves at a random location/* between 20 and 35./* B. Alternating between the two halves move a random number of /* Playing_Card structures to the original deck structure, Until/* it is full of cards

19、(52 cards in a deck).* this is also the /* number of cards available in the to halves./* C. Since it is a full unused deck set the lastdelt variable to -1/* /*/*int x, split; /split 是分开成两部分的位置,如上部分、下部分Center_Text(“Shuffling Deck“);cout m_cardarrayi;topdeckindex+;i+;for(i=(split);im_cardarrayi;bottom

20、deckindex+;i+;int deckoutindex = 0; / set deck to fills index to zeroint numcardstomovetop;int numcardstomovebottom;int j;int h = 0;bottomdeckindex = 52 - split; / set index to num cards in bottomtopdeckindex =split; / set index to num cards in topwhile(deckoutindex 0) / check for available cardsthi

21、s-m_cardarraydeckoutindex = bottomdeck.m_cardarraybottomdeckindex;deckoutindex+;bottomdeckindex-;for(h=0;h 0) deckoutindex+;topdeckindex-;this-m_lastdelt = -1; / Return a complete shuffled deckvoid prog_close()/*/* void prog_close: Waits for user input to end/* Inputs: None/* Returns: None/* Side ef

22、fects: Output text to screen/waits for user input to /* end program./*/* task(s) 1. Pauses Program so the last output can be seen/*/*cout key to Continue“ endl;cout endl endl;Get_Key(); / Necesary for clear input.cin.get();void Deck:Remove_Card()/*/* Deck Remove_Card(Deck deck_1): Removes the card d

23、elt from dealing deck./* Expects: The Deck that delt the card./* Returns: The Deck without the card delt./* Side effects: None./*/* Task(s): Remove card delt from Deck/*m_cardarraym_lastdelt= Playing_Card(); / reinits used card prevents mistakesvoid Deck:Deal_One() /*/* Deck Deal one(Deck):Deals a c

24、ard from the top of the deck /* Expects: A deck to deal from /* Returns: The deck minus the card delt /* Side effects: lastdealt in the deck is incremented /*/* Tasks: 1. Check if lastdealt = 51 if so Error /* 2. Increment last dealt /* 3. Return cardlast dealt /*if(m_lastdelt != 51) / Checks for av

25、ailable cardsm_lastdelt+;cout.width(5);cout “ Card delt“;m_cardarraym_lastdelt.showcard();elsecout “Out of range Error“;prog_close();Deck : Deck() / CONSTRUCTOR replaces default/*/* Deck Deck Class Deck CONSTRUCTOR /* Expects: A deck to deal from /* Returns: The deck minus the card delt /* Side effe

26、cts: lastdealt in the deck is incremented /*/* Tasks: 1. Check if lastdealt = 51 if so Error /* 2. Increment last dealt /* 3. Return cardlast dealt /*int lastdelt = 0;int i;for(i=0;i=51;i+)m_cardarray1 = Playing_Card(); / calls constructor class Playing_Card / for every Playing_Card object in / the class Decks array.

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报