From a9955d617d180fb5f5d3f9f81e2119750afa845d Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Wed, 3 Apr 2019 12:57:52 -0500 Subject: FINISH HW5 YEEEEEE BOIIIIIII --- ee1301/wk5/hw5_directory/strap012_HW5A.cpp | 10 +++ ee1301/wk5/hw5_directory/strap012_HW5B.cpp | 11 +++- ee1301/wk5/hw5_directory/strap012_HW5C.cpp | 101 ++++++++++++++++------------- 3 files changed, 77 insertions(+), 45 deletions(-) (limited to 'ee1301') diff --git a/ee1301/wk5/hw5_directory/strap012_HW5A.cpp b/ee1301/wk5/hw5_directory/strap012_HW5A.cpp index 253be9b..5249ea5 100644 --- a/ee1301/wk5/hw5_directory/strap012_HW5A.cpp +++ b/ee1301/wk5/hw5_directory/strap012_HW5A.cpp @@ -1,3 +1,13 @@ +/* +Date: April 4 2019 +Name: Matthew Strapp +Student ID number: 5449340 +Course number: EE 1301 +Term: Spring 2019 +Lab/assignment number: HW 5A +Short Program Description: Maze Runner 2.0 +*/ + #include #include #include diff --git a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp index 8508283..433f09e 100644 --- a/ee1301/wk5/hw5_directory/strap012_HW5B.cpp +++ b/ee1301/wk5/hw5_directory/strap012_HW5B.cpp @@ -1,5 +1,14 @@ +/* +Date: April 4 2019 +Name: Matthew Strapp +Student ID number: 5449340 +Course number: EE 1301 +Term: Spring 2019 +Lab/assignment number: HW 5B +Short Program Description: Random Array +*/ + #include -#include #include using namespace std; diff --git a/ee1301/wk5/hw5_directory/strap012_HW5C.cpp b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp index 716c413..1b1d10d 100644 --- a/ee1301/wk5/hw5_directory/strap012_HW5C.cpp +++ b/ee1301/wk5/hw5_directory/strap012_HW5C.cpp @@ -1,9 +1,16 @@ +/* +Date: April 4 2019 +Name: Matthew Strapp +Student ID number: 5449340 +Course number: EE 1301 +Term: Spring 2019 +Lab/assignment number: HW 5C +Short Program Description: Pixel Averaging +*/ #include #include #include -#include using namespace std; -ifstream fin; #define SIZE 100 int maxRow = -1, maxColumn = 0; @@ -13,7 +20,6 @@ void pixelAverage(int inArray[SIZE][SIZE], int outArray[SIZE][SIZE]); void printArray(int array[SIZE][SIZE]); int main() { - fin.open("testData.txt"); int inputArray[SIZE][SIZE] = {0}, outputArray[SIZE][SIZE] = {0}; getInput(inputArray); @@ -22,9 +28,13 @@ int main() { printArray(outputArray); } +// Function: getInput +// --------------------------- +// Takes the stream of stdin, puts that into a stringsream and puts that stringsteam into an integer array +// input: an empty array of SIZE, as defined in line 15. void getInput(int input[SIZE][SIZE]) { string test, temp1; int temp2=0; - //I would mainly like to thank some random person on StackOverflow for solving my problem + //I would mainly like to thank whatever user on StackOverflow solved my problem while (getline(cin,test)) { temp2 = -2; istringstream ss(test); @@ -40,77 +50,80 @@ void getInput(int input[SIZE][SIZE]) { maxRow++; } +// Function: makeNewArray +// --------------------------- +// Takes the array made in getInput and puts that same array into a new array to manipulate +// oldArray: Array generated in getInput of SIZE +// newArray: Array of same dimensions and data void makeNewArray(int oldArray[SIZE][SIZE], int newArray[SIZE][SIZE]) { - for (int i = 0; i < SIZE-1; i++) { - for (int j = 0; j < SIZE-1; j++) { - newArray[i][j] = oldArray[i-1][j-1]; + for (int row = 0; row < SIZE-1; row++) { + for (int column = 0; column < SIZE-1; column++) { + newArray[row][column] = oldArray[row-1][column-1]; } } } +// Function: pixelAverage +// --------------------------- +// The meat of the program, taking the surrounding values, adding them, and divides by the number of surrounding values +// inArray: Generated in getInput +// outArray: Generated in makeNewArray void pixelAverage(int inArray[SIZE][SIZE], int outArray[SIZE][SIZE]) { - int sum = 0, n = 0, average, timesRan=0; //n is the number of surrounding pixels - for (int i = -1; i < maxRow-1; i++) { - for (int j = -1; j < maxColumn-1; j++) { - sum=0; n=0; - if ( !((i-1)<1) ) { - cout << "LEFT)" << inArray[i-1][j] << " "; - sum += inArray[i-1][j]; + int sum = 0, n = 0, average; //n is the number of surrounding pixels + for (int row = -1; row < maxRow-1; row++) { + for (int column = -1; column < maxColumn-1; column++) { + sum=0; n=0; //Sum and n are reset every loop + if ( !((row)<0) ) { //True when array is in lower bounds row-wise + sum += inArray[row-1][column]; n++; } - if ( (i+1)