-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrices.cpp
More file actions
158 lines (131 loc) · 4.88 KB
/
matrices.cpp
File metadata and controls
158 lines (131 loc) · 4.88 KB
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
// Program: Assignment 1 - Problem 0
// Purpose: Operator overloading for matrices
// Author: Suhail Hany - Abdelrahman Morsi - Shahesta Alkady
// Date: 30 October 2018
// Version: 1.0
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int data1 [] = {1,2,3,4,5,6,7,8};
int data2 [] = {13,233,3,4,5,6};
int data3 [] = {10,100,10,100,10,100,10,100};
int row,col;
matrix mat1(4,2,data1), mat2(2,4,data2), mat3(4,2,data3);
int choice , scaler;
while(1)
{
cout << "Do you want to enter a matrix ?" << endl
<< "1- Yes" << endl
<< "2- No" << endl;
cin >> choice;
if(choice == 1)
{
cout << "Which matrix do you want to insert " << endl
<< "1- Mat1" << endl
<< "2- Mat2" << endl;
cin >> choice;
if(choice == 1)
cin >> mat1;
else if(choice == 2)
cin >> mat2;
else
cout << "wrong input" << endl;
}
cout << "What do you want to do today ? " << endl
<< "1- Mat1 + Mat2 " << endl
<< "2- Mat1 - Mat2 " << endl
<< "3- Mat1 * Mat2 " << endl
<< "4- Mat1 + scaler " << endl
<< "5- Mat1 - scaler " << endl
<< "6- Mat1 * scaler " << endl
<< "7- Mat1 += Mat2" << endl
<< "8- Mat1 -= Mat2" << endl
<< "9- Mat1 ++ " << endl
<< "10- Mat1 --" << endl
<< "11- Print Mat1" << endl
<< "12- Mat1 == Mat2" << endl
<< "13- Mat1 != Mat2" << endl
<< "14- is Mat1 Square ? " << endl
<< "15- is Mat1 Symmetric ?" << endl
<< "16- is Mat1 identity ?" << endl
<< "17- Matrix transpose " << endl << endl;
cin >> choice;
if(choice == 1) // Mat1 + Mat2
cout << mat1+mat2 << endl;
else if(choice == 2) // Mat1 - Mat2
cout << mat1-mat2 << endl;
else if(choice == 3) // Mat1 * Mat2
{
if(mat1.col == mat2.row)
cout << mat1*mat2 << endl;
else
cout << "Can't Multiply " << endl;
}
else if(choice == 4) // Mat1 + scaler
{
cout << "Enter the scaler " << endl;
cin >> scaler;
cout << mat1 + scaler << endl;
}
else if(choice == 5) // Mat1 - scaler
{
cout << "Enter the scaler " << endl;
cin >> scaler;
cout << mat1 - scaler << endl;
}
else if(choice == 6) // Mat1 * scaler
{
cout << "Enter the scaler " << endl;
cin >> scaler;
cout << mat1 * scaler << endl;
}
else if(choice == 7) // mat1 += mat2
cout << (mat1 += mat2) << endl;
else if(choice == 8) // mat1 -= mat2
cout << (mat1 -= mat2) << endl;
else if(choice == 9) // mat1 ++
{
++mat1;
cout << mat1 << endl;
}
else if(choice == 10) // mat1 --
{
--mat1;
cout << mat1;
}
else if(choice == 11) // Print mat1
cout << mat1 << endl;
else if(choice == 12) // mat1 == mat2
if(mat1 == mat2)
cout << "Yes" << endl;
else
cout << "No" << endl;
else if( choice == 13) // mat1 != mat2
if(mat1 != mat2)
cout << "Yes" << endl;
else
cout << "No" << endl;
else if(choice == 14) // is Mat1 square
if(mat1.isSquare()))
cout << "Yes" << endl;
else
cout << "No" << endl;
else if(choice == 15) // is mat1 symmetric
if(mat1.isSummetric())
cout << "Yes" << endl;
else
cout << "No" << endl;
else if(choice == 16) // is mat1 Identity
if(mat1.isIdentity())
cout << "Yes" << endl;
else
cout << "No" << endl;
else if(choice == 17) // transpose mat1
cout << mat1.transpose() << endl;
else
cout << "Wrong Input" << endl;
}
return 0;
}