diff options
Diffstat (limited to 'functionsHarris-Toovy.cpp')
| -rw-r--r-- | functionsHarris-Toovy.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/functionsHarris-Toovy.cpp b/functionsHarris-Toovy.cpp new file mode 100644 index 0000000..393dc4e --- /dev/null +++ b/functionsHarris-Toovy.cpp @@ -0,0 +1,100 @@ +//Code by Jordan Harris-Toovy for OIT's CST116-01P project 3, December 2021 +#include "mainHeader.h" + +//Gets an input from the user. If it not an int, returns false and sets input to 0 +bool getInt(int& innum) +{ + bool valid = true; + + cin >> innum; + + if (!cin.good()) // Check if the input was an int + { + cin.clear(); //Clear failure condition flag + cin.ignore(numeric_limits<streamsize>::max(), '\n'); //Clears until next \n + + valid = false; + innum = 0; + } + + return valid; +} + +//Returns the amplitude of the largest number in a 3x3 float array +int findMax(float arr[3][3]) +{ + int max = 0; + + for (int idx = 0; idx < 3; idx++) + { + for (int idy = 0; idy < 3; idy++) + { + if (abs(arr[idx][idy]) > max) + { + max = ceil(abs(arr[idx][idy])); + } + } + } + + return max; +} + +//Displays three 3x3 float arrays with a char between the fist two and a = between the last two +void displayTriArray(float arr1[3][3], float arr2[3][3], float arr3[3][3], char sym) +{ + int displayWidth = 0, floatWidth = 0, amplitude = 0, magnitude = 1; + char pipe = (char)179; + + amplitude = findMax(arr1); + if (amplitude < findMax(arr2)) + { + amplitude = findMax(arr2); + } + if (amplitude < findMax(arr3)) + { + amplitude = findMax(arr3); + } //Find the largest number in all arrays + + while ((amplitude /= 10) > 1) + { + magnitude++; + } //Compute the power of the largest number + + floatWidth = magnitude + 5; + displayWidth = floatWidth * 3 + 3; //Add extra space to the visual rows if numbers are large + + cout << fixed << showpos << setprecision(2); //Setup number formatting + + + cout << (char)218 << setw(displayWidth); + cout << (char)191 << " " << (char)218 << setw(displayWidth); + cout << (char)191 << " " << (char)218 << setw(displayWidth); + cout << (char)191 << "\n"; //Top visual row + + cout << pipe << setw(floatWidth) << arr1[0][0] << ' ' << setw(floatWidth) << arr1[0][1] << ' ' << setw(floatWidth) << arr1[0][2] << pipe; + cout << " "; + cout << pipe << setw(floatWidth) << arr2[0][0] << ' ' << setw(floatWidth) << arr2[0][1] << ' ' << setw(floatWidth) << arr2[0][2] << pipe; + cout << " "; + cout << pipe << setw(floatWidth) << arr3[0][0] << ' ' << setw(floatWidth) << arr3[0][1] << ' ' << setw(floatWidth) << arr3[0][2] << pipe; + cout << "\n"; //Top data row + + cout << pipe << setw(floatWidth) << arr1[1][0] << ' ' << setw(floatWidth) << arr1[1][1] << ' ' << setw(floatWidth) << arr1[1][2] << pipe; + cout << ' ' << sym << ' '; + cout << pipe << setw(floatWidth) << arr2[1][0] << ' ' << setw(floatWidth) << arr2[1][1] << ' ' << setw(floatWidth) << arr2[1][2] << pipe; + cout << " = "; + cout << pipe << setw(floatWidth) << arr3[1][0] << ' ' << setw(floatWidth) << arr3[1][1] << ' ' << setw(floatWidth) << arr3[1][2] << pipe; + cout << "\n"; //Middle data row + + cout << pipe << setw(floatWidth) << arr1[2][0] << ' ' << setw(floatWidth) << arr1[2][1] << ' ' << setw(floatWidth) << arr1[2][2] << pipe; + cout << " "; + cout << pipe << setw(floatWidth) << arr2[2][0] << ' ' << setw(floatWidth) << arr2[2][1] << ' ' << setw(floatWidth) << arr2[2][2] << pipe; + cout << " "; + cout << pipe << setw(floatWidth) << arr3[2][0] << ' ' << setw(floatWidth) << arr3[2][1] << ' ' << setw(floatWidth) << arr3[2][2] << pipe; + cout << "\n"; //Bottom data row + + cout << (char)192 << setw(displayWidth); + cout << (char)217 << " " << (char)192 << setw(displayWidth); + cout << (char)217 << " " << (char)192 << setw(displayWidth); + cout << (char)217 << "\n"; //Bottom visual row + +}
\ No newline at end of file |