Print out card deck for suits

I've been given a starting code to create the card for each suits, so far it only shows the 13 cards for the Hearts deck, but I need to expand it to create the cards for all the suits. Other than put DIAMONDS, SPADE, CLUBS in the enum array, I'm at a lost of to how to display another deck.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 

#include "pch.h"
#include <iostream>

using namespace std;

#define NUMBER_OF_CARDS 52 

enum SUIT { HEARTS}; 

struct Card {
	SUIT suit;      // H, D, S, C        
	int value;      // A, 2,3,4,5,6,7,8,9,10, j,q,k        
	int score;      // A = 1, 2 = 2, Q = 10 
};

Card Pack[NUMBER_OF_CARDS]; 

void SetupPack(); 

void SetupHearts(); 



void displayPack(); 





int main() 
{        
	SetupPack();       
displayPack();

system("pause"); 
return 0;
} 
void SetupPack() 
{ 
	SetupHearts();

	
} 
void SetupHearts()
{
	for (int loop = 0; loop <= 12; loop++)
	{
		Pack[loop].suit = HEARTS;
		Pack[loop].value = loop + 1;
		Pack[loop].score = loop + 1;
	}
	// score for jack, queen, king       
	Pack[10].score = 10;
	Pack[11].score = 10;
	Pack[12].score = 10;
}




void displayPack() 
{        
	for (int loop = 0; loop < NUMBER_OF_CARDS; loop++)        
{               
	cout << " Suit = " << Pack[loop].suit;               
	cout << " Score = " << Pack[loop].score;               
	cout << " Value = " << Pack[loop].value;               
	cout << endl;        
} 
}

Last edited on
closed account (E0p9LyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <array>
#include <iostream>
#include <numeric>
#include <random>
#include <chrono>


std::default_random_engine& urng();
void randomize();

int main()
{
   // create a C++11 random engine and randomize it
   randomize();

   // create an alias:
   using card = unsigned short;

   constexpr card NUM_CARDS = 52;

   // manufacture a deck of 52 cards.....

   // create a 52 card std:array deck, initializing all elements to zero:
   std::array<card, NUM_CARDS> deck {0};

   // "populate" the deck, from zero to 51:
   std::iota(deck.begin(), deck.end(), 0);

   // shuffle the deck:
   std::shuffle(deck.begin(), deck.end(), urng());

   // create 2 lambda functions to help display each card in the deck:
   auto rank = [](card c) { return "AKQJT98765432"[c % 13]; };
   auto suit = [](card c) { return "SHDC"[c / 13]; };

   card count = 0;

   std::cout << "Displaying 4 hands of 13 cards:\n\n";

   for (const card& c : deck)
   {
      std::cout << rank(c) << suit(c) << ' ';
      count++;

      // have 13 cards been displayed?
      if (0 == (count % 13))
      {
         std::cout << '\n';
      }
   }
   std::cout << '\n';

}


std::default_random_engine& urng()
{
   static std::default_random_engine URNG { };
   return URNG;
}

void randomize()
{
   unsigned seed;

   seed = static_cast<unsigned> (std::chrono::system_clock::now().time_since_epoch().count());

   urng().seed(seed);
}

(Each run of the program will give a different shuffled deck:)
Displaying 4 hands of 13 cards:

AD 2C KD 4D 3D 8D KC 7D 3S 5C 6H QD TS
JC AH JS 6S QC KS 7C 6C 6D QS JH 2D 8H
TD 5H 4S 5S QH 4C AC 5D 4H AS KH 7H 7S
TH 9H 8S 2H 9D 3H 3C TC 2S 9S 9C JD 8C
Topic archived. No new replies allowed.