diff options
author | Matt Strapp <matt@mattstrapp.net> | 2022-05-24 11:18:46 -0500 |
---|---|---|
committer | Matt Strapp <matt@mattstrapp.net> | 2022-05-24 11:19:55 -0500 |
commit | 7a73162607544204032aa66cce755daf21edebda (patch) | |
tree | 58578e01f15f34a855d99c32898db9d7a1603e67 /OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp | |
parent | do some stuff (diff) | |
download | homework-7a73162607544204032aa66cce755daf21edebda.tar homework-7a73162607544204032aa66cce755daf21edebda.tar.gz homework-7a73162607544204032aa66cce755daf21edebda.tar.bz2 homework-7a73162607544204032aa66cce755daf21edebda.tar.lz homework-7a73162607544204032aa66cce755daf21edebda.tar.xz homework-7a73162607544204032aa66cce755daf21edebda.tar.zst homework-7a73162607544204032aa66cce755daf21edebda.zip |
Graduate
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp')
-rw-r--r-- | OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp b/OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp deleted file mode 100644 index 9f5e285..0000000 --- a/OLD/ee1301/wk6/lab5/strap012_lab5_w_1.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include <iostream>
-//#include <time.h> //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; j<size; j++) {
- hand[j]=deck.dealCard();
- }
- showHand(hand, size);
- }
-}
-
-//Prints out hand shuffled from before
-void showHand(int hand[], const int size) {
- for (int i=0; i<size; i++) {
- //Switch case needed for showing face cards and aces
- switch(hand[i]%13) {
- case 0: std::cout << 'A';
- break;
- case 10: std::cout << 'J';
- break;
- case 11: std::cout << 'Q';
- break;
- case 12: std::cout << 'K';
- break;
- default: std::cout << hand[i]%13+1;
- }
- std::cout << " ";
- }
- std::cout << std::endl;
-}
-
-//Deck initialized with 1-52 and shuffled
-DeckOfCards::DeckOfCards() {
- for(int i=0; i<51; i++) {
- deck[i]=i+1;
- }
- shuffle();
-}
-
-//Implementation of Knuth Shuffle
-void DeckOfCards::shuffle() {
- int j=0, temp=0;
- for (int i=50; i>1; 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 |