-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrassen.cpp
158 lines (138 loc) · 4.04 KB
/
strassen.cpp
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
/*
* strassen.cpp
*/
#include "./includes/strassen.h"
void StrassenLauncher()
{
// welcome menu
cout << " WELCOME TO STRASSEN IMPLEMENTATION " << endl;
cout << " YOU'RE ABLE TO MULTIPLY TWO SQUARE MATRIX " << endl;
cout << " YOU JUST NEED TO ENTER PATH OF DIFFERENTS " << endl;
cout << " MATRIX WITH THE FOLLOWING STRUCTURE " << endl;
cout << " SQUARE_DIM " << endl;
cout << " ITEM_11,ITEM_12,...,ITEM_1SQUARE_DIM " << endl;
cout << " ITEM_21,ITEM_22,...,ITEM_2SQUARE_DIM " << endl;
cout << " ITEM_31,ITEM_32,...,ITEM_3SQUARE_DIM " << endl;
cout << " ITEM_SQUARE_DIM1,ITEM_SQUARE_DIM2,...,ITEM_SQUARE_DIMSQUARE_DIM " << endl;
cout << " LET'S START " << endl;
// variables and constant declaration
// bool flag = false;
Matrix m1,m2,mf;
StrassenActionOption(m1, m2, mf);
}
bool StrassenTryParse(string &input, int &output)
{
try
{
output = stoi(input);
}
catch (invalid_argument)
{
return false;
}
return (output >= 0 && output < 8);
}
void StrassenActionMenu()
{
cout << "\n\n HIT THE NUMBER BEHIND THE ACTION TO LAUNCH " << endl;
cout << " 1) LOAD MATRIX 1 " << endl;
cout << " 2) LOAD MATRIX 2 " << endl;
cout << " 3) PRINT MATRIX 1 " << endl;
cout << " 4) PRINT MATRIX 2 " << endl;
cout << " 5) STRASSEN(MATRIX1,MATRIX2) " << endl;
cout << " 6) SAVE RESULT MATRIX " << endl;
cout << " 7) PRINT RESULT MATRIX " << endl;
cout << " 0) EXIT " << endl;
}
void StrassenActionOption(Matrix &m1, Matrix &m2, Matrix &mf)
{
int option = -1;
string action;
do{
// always show action option to users
StrassenActionMenu();
// get users option from command line
// gettng path
do
{
cout << "\n CHOOSE YOUR ACTION " << endl;
action = getInputUser();
// cout << tryParse(action, option) << option << endl;
} while (StrassenTryParse(action, option) == false);
// custom action for each action choose
switch (option)
{
case 0:
// Exiting message
cout << " THANKS FOR YOUR RELIABILITY AND GOOD BYE " << endl;
break;
case 1:
// code load 1
StrassenLoadMatrix(m1);
break;
case 2:
// code load 2
StrassenLoadMatrix(m2);
break;
case 3:
// code print 1
Matrix::printMatrix(m1);
break;
case 4:
// code print 2
Matrix::printMatrix(m2);
break;
case 5:
// code strassen
Matrix::PreActed(m1,m2);
mf = Matrix::strasseMult(m1,m2);
break;
case 6:
// code save result
StrassenSaveMatrix(mf);
break;
case 7:
// code print result
Matrix::printMatrix(mf);
break;
default:
// code default
break;
}
}while(option != 0);
// Exiting message
}
void StrassenLoadMatrix(Matrix &m)
{
string path;
bool flag = false;
// load first matrix
do
{
// gettng path
do
{
cout << "\n PLEASE HIT THE FIRST MATRIX PATH " << endl;
path = getInputUser();
} while (path.length() == 0);
flag = Matrix::readMatrix(m, path);
flag ? cout << " PROCESS COMPLETED\n" : cout << " AND ERROR OCCUR\n";
} while (flag == false);
}
void StrassenSaveMatrix(Matrix &m)
{
string path;
bool flag = false;
// load first matrix
do
{
// gettng path
do
{
cout << "\n PLEASE HIT THE RESULT MATRIX PATH " << endl;
path = getInputUser();
} while (path.length() == 0);
flag = Matrix::writeMatrix(m, path);
flag ? cout << " PROCESS COMPLETED\n" : cout << " AND ERROR OCCUR\n";
} while (flag == false);
}