aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk6
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
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 '')
-rw-r--r--ee1301/wk6/hw6_directory/strap012_HW6A.cpp12
-rw-r--r--ee1301/wk6/hw6_directory/strap012_HW6B.cpp2
-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
7 files changed, 131 insertions, 7 deletions
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<rounds; j++) {
int curRoll=0;
- numRolls+=1.0;
+ numRolls+=1;
for(int i=1; i < pairs[0]; i+=2) {
- die[i-1] = Dice(pairs[i], pairs[i + 1]);
- roll[i-1] = die[i-1].roll(pairs[i], pairs[i+1]);
+ die = Dice(pairs[i], pairs[i + 1]);
+ roll[i-1] = die.roll();
curRoll += roll[i-1];
}
@@ -90,7 +90,7 @@ int* userInputParser(string s) {
string data[4*maxNumDie]; // Intermediate storage for parsing input string
- // count how many '+'s or 'd's there are...
+ // count how many '+'s or 'd's the roll[i-1] = die[i-1].roll();re are...
int parts = 0;
for(unsigned int i=0; i < s.length(); i++)
{
diff --git a/ee1301/wk6/hw6_directory/strap012_HW6B.cpp b/ee1301/wk6/hw6_directory/strap012_HW6B.cpp
index b4d7636..87ba640 100644
--- a/ee1301/wk6/hw6_directory/strap012_HW6B.cpp
+++ b/ee1301/wk6/hw6_directory/strap012_HW6B.cpp
@@ -28,7 +28,7 @@ int ff(int x) {
return x*ff(x-2);
}
} else {
- // x is 1
+ // x is 1 (or 0)
return 1;
}
}
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.