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/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 ++++++++ 5 files changed, 124 insertions(+) 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/wk6/lab5') diff --git a/ee1301/wk6/lab5/Bug.cpp b/ee1301/wk6/lab5/Bug.cpp new file mode 100644 index 0000000..337e84b --- /dev/null +++ b/ee1301/wk6/lab5/Bug.cpp @@ -0,0 +1,12 @@ +#include "Bug.hpp" + +int main() { + Bug buggy(10); + buggy.display(); + buggy.move(); + buggy.display(); + buggy.turn(); + buggy.display(); + buggy.move(); + buggy.display(); +} diff --git a/ee1301/wk6/lab5/Bug.hpp b/ee1301/wk6/lab5/Bug.hpp new file mode 100644 index 0000000..f3bfae1 --- /dev/null +++ b/ee1301/wk6/lab5/Bug.hpp @@ -0,0 +1,28 @@ +#include + +#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