-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControl.c
More file actions
312 lines (294 loc) · 7.88 KB
/
Control.c
File metadata and controls
312 lines (294 loc) · 7.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
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
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <conio.h>
#include "A2Matrix.h"
COORD coord = {0, 0};
void gotoxy(int x, int y)
{
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void process_1(int X1, int Y1)
{
char select;
void gotoxy(int x, int y);
system("cls");
gotoxy(X1, Y1 + 7);
gotoxy(X1, Y1 + 1);
printf("Select function");
gotoxy(X1, Y1 + 2);
printf("1. Matrix Processing");
gotoxy(X1, Y1 + 3);
printf("2. User Guide");
gotoxy(X1, Y1 + 4);
printf("3. About this Project");
gotoxy(X1, Y1 + 6);
printf("0. Return to main page");
gotoxy(X1, Y1 + 8);
printf("_");
scanf("%c", &select);
switch (select)
{
case '1':
process_2(X1, Y1);
break;
case '2':
userguide();
process_1(X1, Y1);
break;
case '3':
about();
process_1(X1, Y1);
break;
case '0':
main_logo(X1, Y1);
process_1(X1, Y1);
break;
default:
process_1(X1, Y1);
break;
}
}
void process_2(int X1, int Y1)
{
void gotoxy(int x, int y);
double matrix1[30][30], matrix2[30][30], matrix3[30][30], temp[30][30];
int R1, C1, R2, C2, R3, C3, Rt, Ct;
char select;
system("cls");
gotoxy(X1, Y1 + 1);
printf("Select a matrix operation: ");
gotoxy(X1, Y1 + 2);
printf("1. Check symmetry");
gotoxy(X1, Y1 + 3);
printf("2. Find transpose matrix");
gotoxy(X1, Y1 + 4);
printf("3. Find determinant");
gotoxy(X1, Y1 + 5);
printf("4. Find sum/difference/product");
gotoxy(X1, Y1 + 6);
printf("5. Check identicality");
gotoxy(X1, Y1 + 7);
printf("6. Check contain");
gotoxy(X1, Y1 + 8);
printf("7. Find relation factor");
gotoxy(X1, Y1 + 9);
printf("8. Find Max of matrix");
gotoxy(X1, Y1 + 10);
printf("9. Find Min of matrix");
gotoxy(X1, Y1 + 12);
printf("0. Back");
gotoxy(X1, Y1 + 13);
printf("Q. Quit");
gotoxy(X1, Y1 + 14);
printf("_");
scanf("%c", &select);
switch (select)
{
case '1':
{
note1();
enterRC(matrix1, &R1, &C1, ' ');
enterMatrix(matrix1, R1, C1);
outputMatrix(matrix1, R1, C1);
is_symmetric(matrix1, R1, C1) ? printf("\n\nThe matrix is symmetric\n")
: printf("\n\nThe matrix is not symmetric\n");
QuitReturn(X1, Y1);
break;
}
case '2':
{
note1();
enterRC(matrix1, &R1, &C1, ' ');
enterMatrix(matrix1, R1, C1);
printf("\nInput matrix:\n");
outputMatrix(matrix1, R1, C1);
transpose(matrix1, R1, C1, temp);
printf("\nTranspose matrix:\n");
outputMatrix(temp, C1, R1);
QuitReturn(X1, Y1);
break;
}
case '3':
{
note1();
enterRC(matrix1, &R1, &C1, ' ');
enterMatrix(matrix1, R1, C1);
printf("\nInput matrix:\n");
outputMatrix(matrix1, R1, C1);
printf("\nDeterminant of this matrix is: %lf \n", determinant(matrix1, R1, C1));
QuitReturn(X1, Y1);
break;
}
case '4':
{
note1();
char choice;
fflush(stdin);
printf("\nSelect calculation:\n1. Multiplication \n2. Addition\n3. Subtraction\n__");
scanf("%c", &choice);
printf("\n");
enterRC(matrix1, &R1, &C1, '1');
enterMatrix(matrix1, R1, C1);
printf("\nMatrix 1\n");
outputMatrix(matrix1, R1, C1);
enterRC(matrix2, &R2, &C2, '2');
enterMatrix(matrix2, R2, C2);
printf("\nMatrix 2\n");
outputMatrix(matrix2, R2, C2);
switch (choice)
{
case '1':
{
if (matrix_multiply(matrix1, matrix2, R1, C1, R2, C2, matrix3))
{
printf("\n\nThe matrices can be multiplied\n");
printf("\nProduct matrix: \n");
outputMatrix(matrix3, R2, C2);
}
else
printf("\n\nThe matrices can not be multiplied\n");
break;
}
case '2':
{
if (addition(matrix1, matrix2, R1, C1, R2, C2, matrix3))
{
printf("\n\nThe matrices can be added\n");
printf("\nSum matrix: \n");
outputMatrix(matrix3, R2, C2);
}
else
printf("\n\nThe matrices can not be added\n");
break;
}
case '3':
{
if (subtraction(matrix1, matrix2, R1, C1, R2, C2, matrix3))
{
printf("\n\nThe matrices can be subtracted\n");
printf("\nDifference matrix: \n");
outputMatrix(matrix3, R2, C2);
}
else
printf("\n\nThe matrices can not be subtracted\n");
break;
}
default:
break;
}
QuitReturn(X1, Y1);
break;
}
case '5':
{
note1();
enterRC(matrix1, &R1, &C1, '1');
enterMatrix(matrix1, R1, C1);
printf("\nMatrix 1\n");
outputMatrix(matrix1, R1, C1);
enterRC(matrix2, &R2, &C2, '2');
enterMatrix(matrix2, R2, C2);
printf("\nMatrix 2\n");
outputMatrix(matrix2, R2, C2);
is_thesame(matrix1, matrix2, R1, C1, R2, C2) ? printf("\n\nTwo matrices are identical\n")
: printf("\n\nTwo matrices are different\n");
QuitReturn(X1, Y1);
break;
}
case '6':
{
note1();
enterRC(matrix1, &R1, &C1, '1');
enterMatrix(matrix1, R1, C1);
printf("\nMatrix 1\n");
outputMatrix(matrix1, R1, C1);
enterRC(matrix2, &R2, &C2, '2');
enterMatrix(matrix2, R2, C2);
printf("\nMatrix 2\n");
outputMatrix(matrix2, R2, C2);
switch (is_contain(matrix1, matrix2, R1, C1, R2, C2))
{
case 1:
printf("\n\nMatrix 1 contains matrix 2\n");
break;
case 2:
printf("\n\nMatrix 2 contains matrix 1\n");
break;
case 0:
printf("\n\nMatrix 1 and matrix 2 have no relation\n");
break;
default:
break;
}
QuitReturn(X1, Y1);
break;
}
case '7':
{
note1();
enterRC(matrix1, &R1, &C1, '1');
enterMatrix(matrix1, R1, C1);
printf("\nMatrix 1\n");
outputMatrix(matrix1, R1, C1);
enterRC(matrix2, &R2, &C2, '2');
enterMatrix(matrix2, R2, C2);
printf("\nMatrix 2\n");
outputMatrix(matrix2, R2, C2);
relationFactor(matrix1, matrix2, R1, C1, R2, C2);
QuitReturn(X1, Y1);
break;
}
case '8':
{
note1();
enterRC(matrix1, &R1, &C1, ' ');
enterMatrix(matrix1, R1, C1);
outputMatrix(matrix1, R1, C1);
printf("\n\nMax of this matrix is %lf\n", MaxOfMatrix(matrix1, R1, C1));
QuitReturn(X1, Y1);
break;
}
case '9':
{
note1();
enterRC(matrix1, &R1, &C1, ' ');
enterMatrix(matrix1, R1, C1);
outputMatrix(matrix1, R1, C1);
printf("\n\nMin of this matrix is %lf\n", MinOfMatrix(matrix1, R1, C1));
QuitReturn(X1, Y1);
break;
}
case '0':
process_1(X1, Y1);
break;
case 'Q':
case 'q':
QuitReturn(X1, Y1);
break;
default:
process_2(X1, Y1);
break;
}
}
void QuitReturn(int X1, int Y1)
{
printf("\nPress Enter to quit or press R to return _");
char goback;
fflush(stdin);
scanf("%c", &goback);
if (goback == 'R' || goback == 'r')
process_1(X1, Y1);
else
{
system("cls");
gotoxy(X1, Y1 + 7);
printf("!!!Good Bye!!!\n\n\n\n\n\n\n");
getch();
system("cls");
return;
}
}