aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk6/lab5
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2020-01-30 16:55:04 -0600
committerRossTheRoss <mstrapp@protonmail.com>2020-01-30 16:55:04 -0600
commit175721a63b426355274fa9e8063f762020ab8362 (patch)
treecf2c1b33233d660c9f50de5e659b9343bb264984 /ee1301/wk6/lab5
parentMake Python thing in Python (diff)
downloadhomework-175721a63b426355274fa9e8063f762020ab8362.tar
homework-175721a63b426355274fa9e8063f762020ab8362.tar.gz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.bz2
homework-175721a63b426355274fa9e8063f762020ab8362.tar.lz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.xz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.zst
homework-175721a63b426355274fa9e8063f762020ab8362.zip
R E A R R A N G E
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/momentum.cpp28
-rw-r--r--ee1301/wk6/lab5/strap012_lab5_w_1.cpp75
-rw-r--r--ee1301/wk6/lab5/vectorArray.cpp43
-rw-r--r--ee1301/wk6/lab5/wUp.cpp27
-rw-r--r--ee1301/wk6/lab5/warmup.txt15
7 files changed, 0 insertions, 228 deletions
diff --git a/ee1301/wk6/lab5/Bug.cpp b/ee1301/wk6/lab5/Bug.cpp
deleted file mode 100644
index b4ef154..0000000
--- a/ee1301/wk6/lab5/Bug.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#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
deleted file mode 100644
index cc704ab..0000000
--- a/ee1301/wk6/lab5/Bug.hpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#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/momentum.cpp b/ee1301/wk6/lab5/momentum.cpp
deleted file mode 100644
index dfbaeee..0000000
--- a/ee1301/wk6/lab5/momentum.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-#include <iostream>
-
-double momentum (double velocity, double mass);
-
-int main() {
- double velocity[3];
- double mass;
- std::cout << "Please enter velocity (x y z) [m/s]: ";
- std::cin >> velocity[0] >> velocity[1] >> velocity [2];
- std::cout << "Please enter mass [kg]: ";
- std::cin >> mass;
-
- double* vector;
- vector = new double[3];
- std::cout << "Momentum: <";
- for (int i=0; i<=2; i++) {
- vector[i]=momentum(velocity[i], mass);
- std::cout << vector[i];
- if ((i<2))
- std::cout << ",";
- }
- delete[] vector;
- std::cout << ">" << std::endl;
-}
-
-double momentum(double velocity, double mass) {
- return velocity * mass;
-} \ No newline at end of file
diff --git a/ee1301/wk6/lab5/strap012_lab5_w_1.cpp b/ee1301/wk6/lab5/strap012_lab5_w_1.cpp
deleted file mode 100644
index 9f5e285..0000000
--- a/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
diff --git a/ee1301/wk6/lab5/vectorArray.cpp b/ee1301/wk6/lab5/vectorArray.cpp
deleted file mode 100644
index 92d23bd..0000000
--- a/ee1301/wk6/lab5/vectorArray.cpp
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <iostream>
-
-double randVec();
-double momentum (double velocity);
-int main() {
- srand(time(NULL));
- double sum[3]={0,0,0};
- double* randVel; double* momArray;
- randVel = new double[1000];
- momArray = new double[1000];
- for (int i=0; i<1000; i++) {
- randVel[i]=randVec();
- momArray[i]=momentum(randVel[i]);
- int j=i%3;
- sum[j]+=momArray[i];
- }
- std::cout << '<' << sum[0]/1000.0 << ',' << sum[1]/1000.0 << ',' << sum[2]/1000.0 << '>' << std::endl;
- delete[] randVel;
- delete[] momArray;
-}
-
-
-double randVec() {
- double vector[3];
- for (int i=0; i<3; i++) {
- if (rand()%2+1==1) {
- vector[i]=rand()%100+1.0;
- } else {
- vector[i]=rand()%100*-1.0+1.0;
- }
- }
- return *vector;
-}
-
-double momentum(double velocity) {
- double mass;
- if (rand()%2+1==0) {
- mass=rand()%10+1.0;
- } else {
- mass=rand()%10*-1.0+1.0;
- }
- return mass*velocity;
-} \ No newline at end of file
diff --git a/ee1301/wk6/lab5/wUp.cpp b/ee1301/wk6/lab5/wUp.cpp
deleted file mode 100644
index 0cb3957..0000000
--- a/ee1301/wk6/lab5/wUp.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <iostream>
-using namespace std;
-
-class Point
-{
- public:
-void showPoint( );
-Point( );
-Point(int newX, int newY) {
- xlocation = newX;
- ylocation = newY;
-}
-int xlocation;
-int ylocation;
-} ;
-
-
-int main() {
- int a(1);
- int b(2);
- int *p1;
- p1 = &a;
- Point *p2 = new Point(*p1, b);
- *p1 = p2->ylocation;
- p2->xlocation = 10;
- cout << p2->xlocation << ' ' << *p1 << ' ' << b << ' ' << a << endl;
-} \ No newline at end of file
diff --git a/ee1301/wk6/lab5/warmup.txt b/ee1301/wk6/lab5/warmup.txt
deleted file mode 100644
index e18288c..0000000
--- a/ee1301/wk6/lab5/warmup.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-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. 10 2 2 2
- b. The array is not deleted (memory leak)