diff options
Diffstat (limited to 'main.cpp')
| -rw-r--r-- | main.cpp | 111 |
1 files changed, 103 insertions, 8 deletions
@@ -15,6 +15,9 @@ 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]); +void ClearBuffer(); +void DisplayMenu(int& menu_choice); +void ProcessChoice (int& flag, int menu_choice, int size, float mat1[SIZE][SIZE], float mat2[SIZE][SIZE], float matMult[SIZE][SIZE], float tranMat[SIZE][SIZE], float matSum[SIZE][SIZE]); int main() @@ -24,20 +27,21 @@ int main() float matSum [SIZE][SIZE]; float matMult [SIZE][SIZE]; float tranMat [SIZE][SIZE]; + int menu_choice; + int flag = 1; 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); + while(flag != 0) + { + DisplayMenu(menu_choice); + ProcessChoice(flag, menu_choice, SIZE, mat1, mat2, matMult, tranMat, matSum); + } + + cout << "Thanks for checking out the program!" << endl; return 0; } @@ -62,6 +66,7 @@ void FillMat(int size, float mat[SIZE][SIZE]) { int row, col; float temp; + cout << endl << endl; cout << "Lets build a 3x3 matrix..." << endl; cout << "We will fill in the matrix by row..." << endl; @@ -136,3 +141,93 @@ void MultMat (int size, float mat1[SIZE][SIZE], float mat2[SIZE][SIZE], float ma } } + +void DisplayMenu(int& menu_choice) +{ + //Displays the menu of functions for the user to choose from. + menu_choice = 0; + cout << "==================================================================\n"; + cout << " MENU" << endl; + cout << "==================================================================\n"; + + cout << "1) Get New Matrices.\n"; + cout << "2) Multiply Matrices.\n"; + cout << "3) Add Matrices.\n"; + cout << "4) Exit.\n"; + cout << "Enter: "; + cin >> menu_choice; + if (menu_choice > 4 || menu_choice < 1) + { + cout << "Invalid Entry. Please enter a number from the options list provided.\n\n\n\n" << endl; + DisplayMenu(menu_choice); + } +} + + +void ProcessChoice (int& flag, int menu_choice, int size, float mat1[SIZE][SIZE], float mat2[SIZE][SIZE], float matMult[SIZE][SIZE], float tranMat[SIZE][SIZE], float matSum[SIZE][SIZE]) +{ + //Takes in user input for menu choice and calls the appropriate function. + string temp; + int check = 1; + ClearBuffer(); + switch(menu_choice) + { + case 1: + FillMat(size, mat1); + FillMat(size, mat2); + cout << "MATRIX ONE..." << endl; + cout << "==================" << endl; + PrintMat(size, mat1); + cout << "==================" << endl; + cout << endl << endl; + cout << "MATRIX TWO..." << endl; + cout << "==================" << endl; + PrintMat(size, mat2); + cout << "==================" << endl; + break; + + case 2: + MultMat(size, mat1, mat2, matMult, tranMat); + cout << "MULTIPLIED MATRIX..." << endl; + cout << "==================" << endl; + PrintMat(size, matMult); + cout << "==================" << endl; + break; + + case 3: + AddMat(size, mat1, mat2, matSum); + cout << "ADDED MATRIX..." << endl; + cout << "==================" << endl; + PrintMat(size, matSum); + cout << "==================" << endl; + break; + + case 4: + cout << "Are you sure you want to exit?" << endl; + check = 0; + break; + + default: + break; + } + + if (check == 0) + { + cout << "Enter 0 to end program.\n" << endl; + cout << "Enter any other number to continue program.\n" << endl; + cin >> flag; + + } + +} + + + +void ClearBuffer() +{ + // clears buffer after menu choice so as not to interfere with the following user inputs. + char c; + do { + c = getchar(); + } while (c != '\n' && c != EOF); +} |