#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
enum Suit { clubs, diamonds, hearts, spades };
const int jack = 11;
const int queen = 12;
const int king = 13;
const int ace = 14;
class card
{
private:
int number;
Suit suit;
public:
card() { }
void set(int n, Suit s)
{
suit = s; number = n;
}
void display();
};
void card::display()
{
if (number >= 2 && number <= 10)
cout << number;
else
{
switch (number)
{
case jack: cout << 'J'; break;
case queen: cout << 'Q'; break;
case king: cout << 'K'; break;
case ace: cout << 'A'; break;
}
}
switch (suit)
{
case clubs: cout << char(5); break;
case diamonds: cout << char(4); break;
case hearts: cout << char(3); break;
case spades: cout << char(6); break;
}
}
void Hand_Display(card*);
int main()
{
card* deck = new card[52];
for (size_t i = 0; i < 52; i++)
{
int num = (i % 13) + 2;
Suit su = Suit(i / 13);
deck[i].set(num, su);
}
srand(time(NULL));
for (size_t i = 0; i < 52; i++)
{
int k = rand() % 52;
card temp = deck[i];
deck[i] = deck[k];
deck[k] = temp;
}
card hand1[13];
card hand2[13];
card hand3[13];
card hand4[13];
for (size_t i = 0; i < 52; i++)
{
if (i < 13)
hand1[i] = deck[i];
if (12 < i && i < 26)
hand2[i - 13] = deck[i];
if (25 < i && i < 39)
hand3[i - 26] = deck[i];
if (38 < i && i < 52)
hand4[i - 39] = deck[i];
}
delete[] deck;
cout << "\nHand1:\n";
Hand_Display(hand1);
cout << "\nHand2:\n";
Hand_Display(hand2);
cout << "\nHand3:\n";
Hand_Display(hand3);
cout << "\nHand4:\n";
Hand_Display(hand4);
return 0;
}
void Hand_Display(card* hand)
{
for (size_t i = 0; i < 13; i++)
{
hand[i].display();
cout << " ";
}
cout << "\n";
}
//for showing suits in console You might need to switch on "dotted font style"
//in console properties
Comments
Leave a comment