// Project3_Hernandez_Schroeder.cpp : This file contains the 'main' function. Program execution begins and ends there. // // Written by Ben Schroeder and Freddy Hernandez // email:benjamin.schroeder@oit.edu // email:freddy.hernandezjimenez@oit.edu // date: 11/23/2021 and periodically updated up to 12/3/2021 // // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Meetings: // 11/23/2021 Via email: Just discussed a potential gameplan for the project. Decided we would individually look over the problem in // the next few days and check back with each other in the next few days as well. // 11/22/2021 Via email: Just went over some basic steps of who is going to start it and best times to meet. // 11/26/2021 Via email: We discussed the psuedoCode. We got together and decided who would do what and how we would go about doing such things, Ben also set up github for us. // 11/30/2021 Via email: Discussed alternative versions for the different functions in the program. Also, decided on the aesthetics of the program display. // 12/02/2021 Via Email: Discussed Freddy's new algorithm for the multiplication function. Also, Discussed finishing up the documentation for the project. // // // // Code Updates: // 11/24/2021 BAS Wrote several functions for the program. // 11/26/2021 FHJ Wrote alternative versions for the functions. // 12/02/2021 Settled on a mix of both versions as the final set of algorithms. // // // // // AGILE QUESTIONS for Benjamin Schroeder // (ie 1)What specific task? 2)What do I know about the specific task? 3)What do I not know about the specific task? ) // 11/24/2021 // 1) I will begin to draw up psuedocode for the functions in the project, // 2) I know how to do most of the operations involved in the project, however, // 3) I do not know how exactly to build the addition and multiplication tables. // 11/26/2021 // 1) I hope to complete all of the algorithms for the functions in the project. // 2) I have a good grip on the Add(), the menuDisplay(), the getMatrices() functions. // 3) I'll have to sit down with the Multiplication function with a piece of paper and work out the intricasies... // I may settle for 9 separate equations for the algoritm ...? // 11/30/2021 // 1) I plan to look over Freddy's functions and see if we can incorporate bits of both of our work into the code. // 2) It looks like all of Freddy's code works just as well as mine did. (save the display format I created) // 3) I'm not sure if we'll use the 'row', 'col' commands or if we'll just use a 3 for the bounds of the for loops // in the addition, and multiplication functions. // 12/02/2021 // 1) I plan to put the finishing touches on the code today // 2) I know were going to use a hybrid of both of our contributions to all of the functions. // 3) I don't see what else we will need to add to this program to meet all of the requirements... It looks rather complete. //12/03/2021 // 1) I plan to invite the graders and Martha Chamberlin to this Github // 2) I know how to get the invitations set up. // 3) Because sometimes there is some confusion about whether the Github links work, I will probably need to send a accompanying // follow-up email to Martha to let her know this Github is open for all of the parties to view. // // // // AGILE QUESTIONS for Freddy Hernandez // (ie 1)What specific task? 2)What do I know about the specific task? 3)What do I not know about the specific task? ) //Nov 24 5:00Am-8:00Am // 1) The specific task I will complete today, I want to be able to lay out all information and plan out a way to start out. // 2) I know what i want to use roughly and how i want to lay things out // 3) I dont know if its the best way to do it, i want to talk to Ben and make sure he is okay with // things or if there is another way we can start things. //Nov 26, 3:00Pm-9:00Pm // 1) The specific task that I want to complete today is i want to be able to finish getting inputs from user and adding them // 2) I do know that i will be using some for loops to get inputs but also for the adding // 3) I dont know how to really start //Nov 28, 12:00Am-2:00Am // 1)The specific task that I want to complete today is I want to be able to set up the multiplication matrix // 2)I do know how the Matrix multiplication works // 3)I dont know how i am going to set it up since I want to be able to do it with some for loops just like the addition part //Dec 1, 7:00Pm-12:00Am // 1)The specific task that I want to be able to complete today is that I want to be able to finish the muliplication matrix // 2)I do know that it does work with for loops but there is a part that isnt making sense to me, i might have // to add another column and maybe another incrementing variable to increment the column // 3)I dont know where that other column is going to be implemnted // // // //Testing Plan: // Enter several types of inputs into the matrices..(ie floats, ints) and compare the outputs to a scientific calculator for accuracy // // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PSUEDOCODE: // // From main(), Display a banner with a brief description of the program... // Ask for the initial two matrices to be either multiplied or added together // then call getMatrices(); // /////////////////////////////////// // void DisplayMenu() // Show menu options // int menuChoice = somenumber // ask for an option between 1 and 4 // record "menuChoice" entered // while ...the option number entered is out of that range // ask for a selection 1-4 // switch case 1-4 // case 1: call getMatrices // case 2: call multiplyMatrices(A,B,C); // case 3: call addMatrices(A,B,C); // case 4: exit the program // // //////////////////////////////////////// // void getMatrices() // ask for individual elements of the first matrix (by row) // ask for individual elements of the second matrix // // print out both matrices on the screen for the user to see // // then call DisplayMenu(); // /////////////////////////////////////////// // void multiplyMatrices(A,B,C) // do the calculation for matrix multiplication (row by row) // // display the 3 matrices A, B, and C (the multiplication result) // // then call DisplayMenu(); // ///////////////////////////////////////////// // void addMatrices(A,B,C) // do the calculation for matrix addition (element by element) // display the 3 matrices A, B, and C (the addition result) // // Then Call DisplayMenu(); to start the program back through // // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include using namespace std; float MatrixA[3][3]{}; float MatrixB[3][3]{}; float MatrixC[3][3]{}; int menuChoice; void DisplayMenu(); void getMatrices(); void multiplyMatrices(float[3][3], float[3][3], float[3][3]); void addMatrices(float MatrixA[3][3], float MatrixB[3][3], float MatrixC[3][3]); int main() { cout << "*****************************************************\n"; cout << " \t 3x3 Matrix Calculator\n"; cout << "*****************************************************\n"; cout << "(Before we start, we need two 3x3 Matrices, A and B)\n"; //Ask for two matrices to do calculations upon getMatrices(); return 0; } void DisplayMenu() { cout << "\t1) Get New Matrices\n"; cout << "\t2) Multiply Matrices\n"; cout << "\t3) Add Matrices\n"; cout << "\t4) Exit\n"; menuChoice = 0; while (menuChoice < 1 || menuChoice>4) { cout << "\nSelect from the menu above: "; cin >> menuChoice; } switch (menuChoice) { case 1: // Get New Matrices { getMatrices(); break; } case 2: // Multiply Matrices { multiplyMatrices(MatrixA, MatrixB, MatrixC); break; } case 3: // Add Metrices { addMatrices(MatrixA, MatrixB, MatrixC); break; } case 4: // Exit the Program { cout << "\tThank You, Good Bye!!\n\n"; break; } } } void getMatrices() { cout << "\nEnter the elements of Matrix A (by row): \n"; for (int i = 0; i < 3; i++) { cout << "row " << i + 1 << "\n"; // ask for elements in rows 1->3 for (int j = 0; j < 3; j++) { cout << "element " << j + 1 << ": "; //iterate through the columns (per row) cin >> MatrixA[i][j]; } } cout << "\nEnter the Elements of Matrix B (by row):" << endl; for (int i = 0; i < 3; i++) { cout << "row " << i + 1 << "\n"; // ask for elements in rows 1->3 for (int j = 0; j < 3; j++) { cout << "element " << j + 1 << ": "; //iterate through the columns (per row) cin >> MatrixB[i][j]; } } // Display the Matrices that were input cout << "\n\n Matrix A:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixA[i][j] << "\t"; } cout << "\n"; } cout << "\n Matrix B:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixB[i][j] << "\t"; } cout << "\n"; } cout << "\n\n"; DisplayMenu(); } void multiplyMatrices(float MatrixA[3][3], float MatrixB[3][3], float MatrixC[3][3]) { /* // One way to do the matrix multiplication (Not used) // Calculate A X B = C (9 equations (one for each element in Result Matrix)) // Top row of C MatrixC[0][0] = (MatrixA[0][0] * MatrixB[0][0]) + (MatrixA[0][1] * MatrixB[1][0]) + (MatrixA[0][2] * MatrixB[2][0]); MatrixC[0][1] = (MatrixA[0][0] * MatrixB[0][1]) + (MatrixA[0][1] * MatrixB[1][1]) + (MatrixA[0][2] * MatrixB[2][1]); MatrixC[0][2] = (MatrixA[0][0] * MatrixB[0][2]) + (MatrixA[0][1] * MatrixB[1][2]) + (MatrixA[0][2] * MatrixB[2][2]); // 2nd row of C MatrixC[1][0] = (MatrixA[1][0] * MatrixB[0][0]) + (MatrixA[1][1] * MatrixB[1][0]) + (MatrixA[1][2] * MatrixB[2][0]); MatrixC[1][1] = (MatrixA[1][0] * MatrixB[0][1]) + (MatrixA[1][1] * MatrixB[1][1]) + (MatrixA[1][2] * MatrixB[2][1]); MatrixC[1][2] = (MatrixA[1][0] * MatrixB[0][2]) + (MatrixA[1][1] * MatrixB[1][2]) + (MatrixA[1][2] * MatrixB[2][2]); // 3rd row of C MatrixC[2][0] = (MatrixA[2][0] * MatrixB[0][0]) + (MatrixA[2][1] * MatrixB[1][0]) + (MatrixA[2][2] * MatrixB[2][0]); MatrixC[2][1] = (MatrixA[2][0] * MatrixB[0][1]) + (MatrixA[2][1] * MatrixB[1][1]) + (MatrixA[2][2] * MatrixB[2][1]); MatrixC[2][2] = (MatrixA[2][0] * MatrixB[0][2]) + (MatrixA[2][1] * MatrixB[1][2]) + (MatrixA[2][2] * MatrixB[2][2]); */ // Another way to do Matrix multiplication for (int i = 0; i < 3; ++i) //Loop from 0 to row order of the first matrix. for (int j = 0; j < 3; ++j) //Loop from 0 to the column order of the second matrix. for (int k = 0; k < 3; ++k) //Loop from 0 to row order of the second matrix. { MatrixC[i][j] += MatrixA[i][k] * MatrixB[k][j]; //MatrixC[i][j]=(whatever is currently in MatrixC[i][j])+(MatrixA[i][k] * matrixB[k][j]) } //print out results // recall Matrix A cout << "\n\t MATRIX MULTIPLICATION\n Matrix A:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixA[i][j] << "\t"; //Prints out MatrixA } cout << "\n"; } // recall Matrix B cout << "\n Matrix B:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixB[i][j] << "\t"; //Prints out MatrixB } cout << "\n"; } // Display Result Matrix C (the product) cout << "\n A X B = C:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixC[i][j] << "\t"; //Prints out MatrixC(product) } cout << "\n"; } cout << "\n\n"; DisplayMenu(); } void addMatrices(float MatrixA[3][3], float MatrixB[3][3], float MatrixC[3][3]) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { MatrixC[i][j] = MatrixA[i][j] + MatrixB[i][j]; } } //print out results // recall Matrix A cout << "\n\t MATRIX ADDITION\n Matrix A:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixA[i][j] << "\t"; } cout << "\n"; } //recall Matrix B cout << "\n Matrix B:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixB[i][j] << "\t"; } cout << "\n"; } //Display Result Matrix C (the sum) cout << "\n A + B = C:\n"; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cout << "\t" << MatrixC[i][j] << "\t"; } cout << "\n"; } cout << "\n\n"; DisplayMenu(); }