aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortylr <[email protected]>2021-12-07 21:56:19 -0800
committertylr <[email protected]>2021-12-07 21:56:19 -0800
commitcb0dc64dda6a083ee8d1d497c7156a6b6e0779fe (patch)
treecdbecb1259d1e2659271a7c485f986c6bb313451
parentAdding cpp file. (diff)
downloadcst116-proj3-till-t-cb0dc64dda6a083ee8d1d497c7156a6b6e0779fe.tar.xz
cst116-proj3-till-t-cb0dc64dda6a083ee8d1d497c7156a6b6e0779fe.zip
All functions working. Need driver menu.
-rw-r--r--main.cpp138
1 files changed, 138 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
index e69de29..d5093f2 100644
--- a/main.cpp
+++ b/main.cpp
@@ -0,0 +1,138 @@
+//tyler taormina
+//cst 116
+//dec 7, 2021
+//Project 3 (Isabella Mon, Tyler Taormina)
+
+
+#include <iostream>
+
+using namespace std;
+
+int const SIZE = 3;
+
+void FillMat (int size, float mat[SIZE][SIZE]);
+void PrintMat (int size, float mat[SIZE][SIZE]);
+void AddMat (int size, float mat1[SIZE][SIZE], float mat2[SIZE][SIZE], float matSum[SIZE][SIZE]);
+void TransMat (int size, float mat[SIZE][SIZE], float tranMat[SIZE][SIZE]);
+void MultMat (int size, float mat1[SIZE][SIZE], float mat2[SIZE][SIZE], float matMult[SIZE][SIZE], float tranMat[SIZE][SIZE]);
+
+
+int main()
+{
+ float mat1 [SIZE][SIZE];
+ float mat2 [SIZE][SIZE];
+ float matSum [SIZE][SIZE];
+ float matMult [SIZE][SIZE];
+ float tranMat [SIZE][SIZE];
+
+ FillMat(SIZE, mat1);
+ FillMat(SIZE, mat2);
+ AddMat(SIZE, mat1, mat2, matSum);
+ cout << "Matrix 1" << endl;
+ PrintMat(SIZE, mat1);
+ cout << "Matrix 2" << endl;
+ PrintMat(SIZE, mat2);
+
+ MultMat(SIZE, mat1, mat2, matMult, tranMat);
+ cout << "Multiplied Matrix" << endl;
+ PrintMat(SIZE, matMult);
+
+
+ return 0;
+}
+
+
+void AddMat(int size, float mat1[SIZE][SIZE], float mat2[SIZE][SIZE], float matSum[SIZE][SIZE])
+{
+ int row, col;
+ float sum;
+
+ for (row = 0; row < size; row++)
+ {
+ for (col = 0; col < size; col++)
+ {
+ sum = mat1[row][col] + mat2[row][col];
+ matSum[row][col] = sum;
+ }
+ }
+}
+
+
+void FillMat(int size, float mat[SIZE][SIZE])
+{
+ int row, col;
+ float temp;
+
+ cout << "Lets build a 3x3 matrix..." << endl;
+ cout << "We will fill in the matrix by row..." << endl;
+ cout << "Input prompts will stop automatically once the matrix is full..." << endl;
+
+ for (row = 0; row < size; row++)
+ {
+ for (col = 0; col < size; col++)
+ {
+ cout << "Please enter a number: ";
+ cin >> temp;
+ mat[row][col] = temp;
+ }
+ }
+}
+
+
+void PrintMat(int size, float mat[SIZE][SIZE])
+{
+ int row, col;
+
+ for (row = 0; row < size; row++)
+ {
+ for (col = 0; col < size; col++)
+ {
+ cout << mat[row][col] << " ";
+ }
+ cout << endl;
+ }
+}
+
+
+void TransMat (int size, float mat[SIZE][SIZE], float tranMat[SIZE][SIZE])
+{
+ int row, col;
+
+ for (row = 0; row < size; row++)
+ {
+ for (col = 0; col < size; col++)
+ {
+ tranMat[row][col] = mat[col][row];
+ }
+ }
+}
+
+
+void MultMat (int size, float mat1[SIZE][SIZE], float mat2[SIZE][SIZE], float matMult[SIZE][SIZE], float tranMat[SIZE][SIZE])
+{
+ int row, col;
+ int i = 0;
+ int k;
+ float temp = 0;
+ float total = 0;
+
+ TransMat(size, mat2, tranMat);
+
+ for (k = 0; k < size; k++)
+ {
+ for (row = 0; row < size; row++)
+ {
+
+ for (col = 0; col < size; col++)
+ {
+ temp = mat1[k][col] * tranMat[i][col];
+ total += temp;
+ }
+ matMult[k][i] = total;
+ i++;
+ total = 0;
+ }
+ i = 0;
+ }
+}
+