From 175721a63b426355274fa9e8063f762020ab8362 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Thu, 30 Jan 2020 16:55:04 -0600 Subject: R E A R R A N G E --- OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp | 75 +++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp (limited to 'OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp') diff --git a/OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp b/OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp new file mode 100644 index 0000000..9f5e285 --- /dev/null +++ b/OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp @@ -0,0 +1,75 @@ +#include +//#include //Needed if using MinGW + +class DeckOfCards { +private: + int index=0, deck[52]; +public: + DeckOfCards(); + void shuffle(); + int dealCard(); +}; + +void showHand(int hand[], const int size); +int main() { + srand(time(NULL)); + const int size=4; //Size can be changed for larger hands + DeckOfCards deck; + int hand[size]; + for (int i=0; i<13; i++) { + for (int j=0; j1; i--) { + j = rand() % 50 + 1; + if (j < i) { + temp=deck[i]; deck[i]=deck[j]; deck[j]=temp; + } + } +} + +//Function to deal the card when asked by grabbing from the deck and shuffling if such card does not exist. +//Returns the card drawn from the deck +int DeckOfCards::dealCard() { + index++; + if (index>=52) { + index=0; + shuffle(); + } + return deck[index]; +} \ No newline at end of file -- cgit v1.2.3