diff options
Diffstat (limited to 'CST116F2021-Proj3/CST116F2021-Proj3.cpp')
| -rw-r--r-- | CST116F2021-Proj3/CST116F2021-Proj3.cpp | 115 |
1 files changed, 103 insertions, 12 deletions
diff --git a/CST116F2021-Proj3/CST116F2021-Proj3.cpp b/CST116F2021-Proj3/CST116F2021-Proj3.cpp index 93999c0..ebc56fb 100644 --- a/CST116F2021-Proj3/CST116F2021-Proj3.cpp +++ b/CST116F2021-Proj3/CST116F2021-Proj3.cpp @@ -1,20 +1,111 @@ -// CST116F2021-Proj3.cpp : This file contains the 'main' function. Program execution begins and ends there. -// +#include "Header.h" + +//HEADER +#pragma once #include <iostream> +#include <iomanip> + +using namespace std; + +//function prototypes +void getNewMatrices(); +void addMatrices(); +void multiplyMatrices(); + +float Matrix1[3][3]; +float Matrix2[3][3]; +//kaeden int main() { - std::cout << "Hello World!\n"; + int menuChoice = 0; + while (menuChoice != 4) + { + cout << "~The Matrix Machine~\n1) Get new matrices.\n2) Multiply Matrices\n3) Add Matrices\n4) Exit\nWhat would you like to do? "; + cin >> menuChoice; + switch (menuChoice) + { + case 1: + getNewMatrices(); + break; + case 2: + multiplyMatrices(); + break; + case 3: + addMatrices(); + break; + case 4: + break; + default: + cout << "Invalid menu choice."; + } + } + cout << "\nGoodbye!\n"; +} + +//kaeden +void multiplyMatrices() +{ + float matrixProduct[3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + matrixProduct[i][j] = (Matrix1[i][0] * Matrix2[0][j]) + (Matrix1[i][1] * Matrix2[1][j]) + (Matrix1[i][2] * Matrix2[2][j]); + } + } + cout << "|" << matrixProduct[0][0] << setw(8) << matrixProduct[0][1] << setw(8) << matrixProduct[0][2] << "|\n"; + cout << "|" << matrixProduct[1][0] << setw(8) << matrixProduct[1][1] << setw(8) << matrixProduct[1][2] << "|\n"; + cout << "|" << matrixProduct[2][0] << setw(8) << matrixProduct[2][1] << setw(8) << matrixProduct[2][2] << "|\n"; + return; } -// Run program: Ctrl + F5 or Debug > Start Without Debugging menu -// Debug program: F5 or Debug > Start Debugging menu +//james +void getNewMatrices() +{ + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + cout << "Value " << (i * 3) + (j + 1) << " of Matrix 1: "; + cin >> Matrix1[i][j]; + } + } + + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + cout << "Value " << (i * 3) + (j + 1) << " of Matrix 2: "; + cin >> Matrix2[i][j]; + } + } +} + +//james +void addMatrices() +{ + float displayMatrix[3][3]; + char upperCornerL = 218, upperCornerR = 191, lowerCornerL = 192, lowerCornerR = 217; + + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + displayMatrix[i][j] = Matrix1[i][j] + Matrix2[i][j]; + } + } -// Tips for Getting Started: -// 1. Use the Solution Explorer window to add/manage files -// 2. Use the Team Explorer window to connect to source control -// 3. Use the Output window to see build output and other messages -// 4. Use the Error List window to view errors -// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project -// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file + cout << upperCornerL << setw(21) << upperCornerR + << endl; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + cout << setw(6) << displayMatrix[i][j]; + } + cout << endl; + } + cout << lowerCornerL << setw(21) << lowerCornerR << endl; +}
\ No newline at end of file |