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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
|
// Project3_Hernandez_Schroeder.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
// Written by Ben Schroeder and Freddy Hernandez
// email:[email protected]
// email:[email protected]
// 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 <iostream>
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();
}
|