aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk6/lab5
diff options
context:
space:
mode:
authorMatthew Strapp <msattr@gmail.com>2019-04-17 17:00:57 -0500
committerMatthew Strapp <msattr@gmail.com>2019-04-17 17:00:57 -0500
commit7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3 (patch)
treeb6cc5690621a08af346d80680edc882bb3631ace /ee1301/wk6/lab5
parentfinish up (diff)
downloadhomework-7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3.tar
homework-7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3.tar.gz
homework-7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3.tar.bz2
homework-7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3.tar.lz
homework-7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3.tar.xz
homework-7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3.tar.zst
homework-7bd0457ece5cfea5e17d6f2ac04508daefc6e4e3.zip
LAB TIME
OH NO
Diffstat (limited to 'ee1301/wk6/lab5')
-rw-r--r--ee1301/wk6/lab5/Bug.cpp12
-rw-r--r--ee1301/wk6/lab5/Bug.hpp28
-rw-r--r--ee1301/wk6/lab5/strap012_lab5_w_1.cpp69
-rwxr-xr-xee1301/wk6/lab5/testbin0 -> 35136 bytes
-rw-r--r--ee1301/wk6/lab5/warmup.txt15
5 files changed, 124 insertions, 0 deletions
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 <iostream>
+
+#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 <iostream>
+#include <string>
+
+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<size; j++) {
+ hand[j]=deck.dealCard();
+ }
+ showHand(hand, size);
+ }
+}
+
+void showHand(int hand[], const int size) {
+
+ for (int i=0; i<size; i++) {
+ char newHand[size];
+ 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;
+}
diff --git a/ee1301/wk6/lab5/test b/ee1301/wk6/lab5/test
new file mode 100755
index 0000000..aa36d7f
--- /dev/null
+++ b/ee1301/wk6/lab5/test
Binary files differ
diff --git a/ee1301/wk6/lab5/warmup.txt b/ee1301/wk6/lab5/warmup.txt
new file mode 100644
index 0000000..6dd4bc2
--- /dev/null
+++ b/ee1301/wk6/lab5/warmup.txt
@@ -0,0 +1,15 @@
+1)
+ a. Line 5 constructs the class with no values.
+ b. It'll work, but it might not work well.
+ c. No.
+ d. Point(int newX, int newY);
+2)
+ a. This changes the value xlocation and ylocation in the Point class to 3 and 10 respectively.
+ This changes the default values.
+ b. The object p1 of the class Point is initialized with an xlocation of 3 and a ylocation of 6.
+ c. The declaration is incorrect.
+ d. Line 6 is a function of return type Point with no input.
+ e. Point p2;
+3)
+ a.
+ b.