From 7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3 Mon Sep 17 00:00:00 2001 From: Matthew Strapp Date: Wed, 17 Apr 2019 17:00:57 -0500 Subject: LAB TIME OH NO --- ee1301/wk6/hw6_directory/strap012_HW6A.cpp | 12 ++--- ee1301/wk6/hw6_directory/strap012_HW6B.cpp | 2 +- ee1301/wk6/lab5/Bug.cpp | 12 +++++ ee1301/wk6/lab5/Bug.hpp | 28 ++++++++++++ ee1301/wk6/lab5/strap012_lab5_w_1.cpp | 69 +++++++++++++++++++++++++++++ ee1301/wk6/lab5/test | Bin 0 -> 35136 bytes ee1301/wk6/lab5/warmup.txt | 15 +++++++ 7 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 ee1301/wk6/lab5/Bug.cpp create mode 100644 ee1301/wk6/lab5/Bug.hpp create mode 100644 ee1301/wk6/lab5/strap012_lab5_w_1.cpp create mode 100755 ee1301/wk6/lab5/test create mode 100644 ee1301/wk6/lab5/warmup.txt (limited to 'ee1301') diff --git a/ee1301/wk6/hw6_directory/strap012_HW6A.cpp b/ee1301/wk6/hw6_directory/strap012_HW6A.cpp index de36cf6..d802c15 100644 --- a/ee1301/wk6/hw6_directory/strap012_HW6A.cpp +++ b/ee1301/wk6/hw6_directory/strap012_HW6A.cpp @@ -15,7 +15,7 @@ private: int min; int max; public: - int roll(int min, int max) { + int roll() { return rand() % (max-min+1) + min; }; Dice() { //Default constructor for debugging purposes @@ -30,7 +30,7 @@ public: int main() { int rounds; - Dice die[maxNumDie]; + Dice die; int roll[maxNumDie]; int max=0, min=999999, sum=0, sample=0; double avg; @@ -54,10 +54,10 @@ int main() { double numRolls=0; for (int j=0; j + +#ifndef BUG_H + +#define BUG_H +class Bug { +private: + int position, dir; +public: + Bug() { + position=0; + dir=1; + } + Bug(int pos) { + position=pos; + dir=1; + } + void move() { + position+=dir; + } + void turn() { + dir*=-1; + } + void display() { + std::cout << "position = " << position << ", direction = " << dir << std::endl; + } +}; +#endif diff --git a/ee1301/wk6/lab5/strap012_lab5_w_1.cpp b/ee1301/wk6/lab5/strap012_lab5_w_1.cpp new file mode 100644 index 0000000..490b54c --- /dev/null +++ b/ee1301/wk6/lab5/strap012_lab5_w_1.cpp @@ -0,0 +1,69 @@ +#include +#include + +class DeckOfCards { +private: + int deck[53]; + int index; +public: + DeckOfCards() { + for(int i=0; i<52; i++) { + deck[i]=i+1; + } + int index=0; + } + int dealCard() { + index++; + if (index>=52) { + index=0; + shuffle(); + } + return deck[index]; + } + void shuffle() { + int j=0; + int temp=0; + for (int i=51; i>1; i--) { + j = rand() % 51 + 1; + if (0 < j && j < i) { + temp=deck[i]; deck[i]=deck[j]; deck[j]=temp; + } + } + } +}; + +void showHand(int hand[], const int size); +char findCard(int card); +int main() { + const int size=4; + srand(time(NULL)); + DeckOfCards deck; + int hand[size]; + deck.shuffle(); + for (int i=0; i<13; i++) { + for (int j=0; j