answersLogoWhite

0


Best Answer

1

2

3

4

5

6

7

8

9

10

//DeckOfCards.h class Deckofcards { public: Deckofcards(); void shuffle(); void deal(); private: int deck[4][13]; };

1

2

3

4

5

6

7

8

9

10

11

//client.cpp #include "DeckOfCards.h" int main() { Deckofcards deckofcards; deckofcards.shuffle(); deckofcards.deal(); return 0; }//end main

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

//Deckofcards.cpp #include <iostream> using std::cout; using std::left; using std::right; #include <iomanip> using std::setw; #include <cstdlib> using std::rand; using std::srand; #include <ctime> using std::time; #include "DeckOfCards.h" Deckofcards::Deckofcards() { for (int row = 0; row <= 3; row++ ) { for (int column = 0; row <= 12; column++) { deck[row][column] = 0; //slot of deck is 0 }//end column for }//end row for srand(time(0));//seed random number }//end Deckofcards constructor void Deckofcards::shuffle() { cout << "hit"; int row; //suit of card int column; //face of card for (int card = 1; card <=52; card++) { do { row = rand()%4; column = rand()%13; } while( deck[row][column] !=0);//end do...while deck [row][column] = card; }//end for }//end shuffle void Deckofcards::deal() { cout << "hit"; static const char *suit[4] = {"Hearts", "Diamonds", "Clovers", "Spades"}; static const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven" , "Eight", "Nine", "Ten", "Jack", "Queen", "King" }; for (int card = 1; card <=52; card++) { for (int row = 0; row <= 3; row++) { for (int column = 0; column <= 12; column++) { if (deck[row][column] == card) { cout << setw(5) << right << face[column] << " of " << setw(8) << left << suit[row] << (card %2 == 0 ? '\n' : '\t'); }//end if }//end for }//end for }//end for }//end deal

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program to represent a deck of playing cards using arrays?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to read your name and reverse it using arrays?

abdulrahman


Write a program to find intersection between two arrays?

#include&lt;stdio.h&gt;


Write a program using iostreams to take as input two multi-dimensional arrays and print their sum as output Matrix Addition in Matrix format?

http://www.assignmentsclub.com/


Can you Write a program in 'c' to print symbols of playing cards?

Yes.


Would you Write c plus plus program using array for Fibonacci number?

You can write a C++ fib pro using arrays but the problem is the prog becomes very complicated since u need to pass the next adding value in an array.....


Write a program demonstrating the usage of pointers with one dimensional and two dimensional arrays?

int main (int,char* argv[]) { int i, for (i=0;i&lt;arg;++i) printf ("% 2d:% s\a";i,argv[i]); return o; }


Is an array is a collection of characters that can be fixed or variable?

No. An array is a collection of objects of any type, such as doubles, not just characters. You can even have arrays of arrays, or arrays of structs. In C, the size of an array is fixed, but it is possible to write code that will allow you to manually make it variable in size.


How to write program for secant method in mathematica?

How to write a program for secant method by mathematica


Write a flowchart to find the sum of maximum and minimum o N natural numbers without using arrays?

huh?


Write a program in Lex to eliminate white space and collect numbers as a token?

write a lex program to delete space from the program


How do you write Square program using vb?

write a vb program to find the magic square


Write a program to multiply 33 matrix.?

write a program to multily 3*3 matrix.