[C ++] oo playing cards

Source: Internet
Author: User

# Include <iostream> <br/> # include <vector> <br/> using namespace STD; </P> <p> Enum suit <br/> {<br/> spade = 0, <br/> heart, <br/> diamond, <br/> club <br/>}; </P> <p> class poker <br/>{< br/> PRIVATE: <br/> suit m_suit; <br/> int m_number; <br/> Public: <br/> poker (suit, int number) <br/>{< br/> m_suit = suit; <br/> m_number = number; <br/>}</P> <p> string getsuit () <br/>{< br/> string suit = "spade "; <Br/> If (m_suit = heart) <br/> suit =" heart "; <br/> If (m_suit = diamond) <br/> suit = "diamond"; <br/> If (m_suit = Club) <br/> suit = "club"; <br/> return suit; <br/>}</P> <p> friend ostream & operator <(ostream & OS, poker * PK) <br/>{< br/> string suit = PK-> getsuit (); <br/> OS <"[" <suit. c_str () <":" <PK-> m_number <"]"; <br/> return OS; <br/>}< br/> }; </P> <p> class cards <br/> {<B R/> PRIVATE: <br/> vector <poker *> m_cards; <br/> Public: <br/> cards () <br/> {<br/> for (INT I = 0; I <52; I ++) <br/>{< br/> m_cards.push_back (new poker (suit) (I/13), (I % 13) + 1 )); <br/>}< br/> void output () <br/>{< br/> vector <poker *> :: iterator iter = m_cards.begin (); <br/> for (; iter! = M_cards.end (); ITER ++) <br/>{< br/> cout <(poker *) (* ITER) <Endl; <br/>}< br/>}; </P> <p> int _ tmain (INT argc, _ tchar * argv []) <br/>{< br/> cards * cards = new cards (); <br/> cards-> output (); <br/> int A = 0; <br/> A = cin. get (); <br/> return 0; <br/>}

 

When I was reading the forum, I saw someone asking me how to make the licensing more oo.

I made a simple oo playing card...

Using poker objects to represent each card has two attributes: Color and number.

Then pack it with cards.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.