aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-04-02 21:43:08 -0500
committerRossTheRoss <msattr@gmail.com>2019-04-02 21:43:08 -0500
commitdd41a64838e2b8d8cecef9d8a278e1ce58f274ee (patch)
tree9e83650cb8563f00b0c2c6dea21598901a783e9a
parentUpdate strap012_HW5C.cpp (diff)
downloadhomework-dd41a64838e2b8d8cecef9d8a278e1ce58f274ee.tar
homework-dd41a64838e2b8d8cecef9d8a278e1ce58f274ee.tar.gz
homework-dd41a64838e2b8d8cecef9d8a278e1ce58f274ee.tar.bz2
homework-dd41a64838e2b8d8cecef9d8a278e1ce58f274ee.tar.lz
homework-dd41a64838e2b8d8cecef9d8a278e1ce58f274ee.tar.xz
homework-dd41a64838e2b8d8cecef9d8a278e1ce58f274ee.tar.zst
homework-dd41a64838e2b8d8cecef9d8a278e1ce58f274ee.zip
Do more work
Diffstat (limited to '')
-rw-r--r--ee1301/wk5/hw5_directory/strap012_HW5B.cpp7
-rw-r--r--ee1301/wk5/hw5_directory/strap012_HW5C.cpp69
-rw-r--r--testData.txt9
3 files changed, 60 insertions, 25 deletions
diff --git a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp
index ca6d150..8508283 100644
--- a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp
+++ b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp
@@ -1,4 +1,5 @@
#include <iostream>
+#include <time.h>
#include <cstdlib>
using namespace std;
@@ -22,9 +23,9 @@ int main(int argc, char *argv[])
for (int curCol = 0; curCol < n; curCol++)
{
if (rand() % 2 + 1 == 2) { //Decide the sign of the number
- randArray[curRow][curCol] = -1 * (rand() % (max+1));
+ randArray[curCol][curRow] = -1 * (rand() % (max+1));
} else {
- randArray[curRow][curCol] = (rand() % (max+1));
+ randArray[curCol][curRow] = (rand() % (max+1));
}
}
}
@@ -34,7 +35,7 @@ int main(int argc, char *argv[])
{
for (int curCol = 0; curCol < n; curCol++)
{
- cout << randArray[curRow][curCol] << " ";
+ cout << randArray[curCol][curRow] << " ";
}
cout << endl;
}
diff --git a/ee1301/wk5/hw5_directory/strap012_HW5C.cpp b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp
index d2d599f..701973a 100644
--- a/ee1301/wk5/hw5_directory/strap012_HW5C.cpp
+++ b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp
@@ -1,38 +1,71 @@
#include <iostream>
#include <string>
#include <sstream>
+#include <fstream>
using namespace std;
+ifstream fin;
#define SIZE 100
int maxRow = 0, maxColumn = 0;
void getInput(int input[SIZE][SIZE]);
+void makeNewArray(int oldArray[SIZE][SIZE], int newArray[SIZE][SIZE]);
+void pixelAverage(int array[SIZE][SIZE]);
+void printArray(int array[SIZE][SIZE]);
+
int main() {
+ fin.open("testData.txt");
int column = 0, row = 0;
- /*
- Array is set up as follows
- C
- R 0 1 ...
- 1
- ...
- */
int inputArray[SIZE][SIZE] = {0};
getInput(inputArray);
-
+ int outputArray[SIZE][SIZE] = {0};
+ makeNewArray(inputArray, outputArray);
+ pixelAverage(outputArray);
+ printArray(outputArray);
}
void getInput(int input[SIZE][SIZE]) {
- string test;
+ string test, temp1; int temp2=0;
//I would mainly like to thank some random person on StackOverflow for solving my problem
- while (getline(cin,test)) {
+ while (getline(fin,test)) {
+ temp2 = 0;
istringstream ss(test);
- string foo; //foo is only needed in this one scope and will not be named further.
- while(getline(ss,foo,' '))
- maxRow=0;
- {
- input[maxRow][maxColumn] = stoi(foo);
- maxRow++;
+ while(getline(ss,temp1,' ')) {
+ temp2++;
+ input[maxRow][temp2] = stoi(temp1);
}
- maxColumn++;
+ if (temp2>maxColumn) {
+ maxColumn = temp2+2; //2 is added to make the math work.
+ }
+ maxRow++;
}
- cout << maxRow << " " << maxColumn << endl;
+ maxRow++;
}
+
+void makeNewArray(int oldArray[SIZE][SIZE], int newArray[SIZE][SIZE]) {
+ for (int i = 0; i < SIZE-1; i++) {
+ for (int j = 2; j < SIZE-1; j++) {
+ newArray[i][j] = oldArray[i-1][j-1];
+ }
+ }
+}
+
+void pixelAverage(int array[SIZE][SIZE]) {
+ for (int i = 0; i < maxRow; i++) {
+ for (int j = 0; j < maxColumn; j++) {
+
+ }
+ }
+}
+
+void printArray (int array[SIZE][SIZE]) {
+ //It is unknown why these for loops do not start at 0.
+ //Since they work for all 2D arrays with size<100, no negative effects are known.
+ for (int j = 1; j < maxRow; j++)
+ {
+ for (int i = 2; i < maxColumn; i++)
+ {
+ cout << array[j][i] << " ";
+ }
+ cout << endl;
+ }
+} \ No newline at end of file
diff --git a/testData.txt b/testData.txt
index b0628c2..d615963 100644
--- a/testData.txt
+++ b/testData.txt
@@ -1,4 +1,5 @@
-33 44 96 -13
--40 -72 -17 -87
--13 -89 11 -51
--3 -64 19 -75
+10 8 8 0 1 -4
+5 9 -9 6 10 6
+10 -4 7 -8 2 -6
+8 0 2 10 -7 4
+-6 10 -9 -10 6 -8