// File: ex8-8.cpp
#include <iostream>
#include <cmath>
using namespace std;
const char suit_char[5] = "CDHS";
const char pips_char[14] = "23456789TJQKA";
class Deck;
class Card
{
private:
int suit;
int pips;
public:
Card(int = 0);
friend ostream& operator<<(ostream&,const Deck&);
};
Card::Card(int x) : suit(x/13), pips(x%13) { }
class Deck
{
private:
Card* d[52];
public:
Deck();
~Deck();
friend ostream& operator<<(ostream&,const Deck&);
};
Deck::Deck()
{
for (int i = 0; i < 52; i++) d[i] = new Card(i);
}
Deck::~Deck()
{
for (int i = 0; i < 52; i++)
{
delete d[i];
d[i] = nullptr;
}
}
int main()
{
Deck Cards;
cout << Cards;
}
ostream& operator<<(ostream& s,const Deck& dk)
{
for (int i = 0; i < 52; i++)
{
s << pips_char[dk.d[i]->pips] << suit_char[dk.d[i]->suit];
if (i % 13 == 12) s << endl;
else s << ' ';
}
return s;
}