aboutsummaryrefslogtreecommitdiffstats
path: root/OLD/ee1301/wk6/lab5/vectorArray.cpp
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 /OLD/ee1301/wk6/lab5/vectorArray.cpp
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 'OLD/ee1301/wk6/lab5/vectorArray.cpp')
-rw-r--r--OLD/ee1301/wk6/lab5/vectorArray.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/OLD/ee1301/wk6/lab5/vectorArray.cpp b/OLD/ee1301/wk6/lab5/vectorArray.cpp
new file mode 100644
index 0000000..92d23bd
--- /dev/null
+++ b/OLD/ee1301/wk6/lab5/vectorArray.cpp
@@ -0,0 +1,43 @@
+#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