aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Proj3/CST116F2021-Proj3.cpp
blob: ebc56fbb750320120ce9f14efaa71a776c1bf0f6 (plain) (blame)
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
#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()
{
    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;
}

//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];
        }
    }

    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;
}