From dd41a64838e2b8d8cecef9d8a278e1ce58f274ee Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Tue, 2 Apr 2019 21:43:08 -0500 Subject: Do more work --- ee1301/wk5/hw5_directory/strap012_HW5B.cpp | 7 +-- ee1301/wk5/hw5_directory/strap012_HW5C.cpp | 69 ++++++++++++++++++++++-------- 2 files changed, 55 insertions(+), 21 deletions(-) (limited to 'ee1301') 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 +#include #include 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 #include #include +#include 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 -- cgit v1.2.3