blob: 393dc4e9163d6833455bcf312cb0d795aed43477 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
}
|