@@ -110,7 +110,11 @@ void Program::start() {
110110 case ' 8' :
111111 case ' 9' :
112112 index = option2 - 53 ;
113- runAlgorithm (index);
113+ try {
114+ runAlgorithm (index);
115+ } catch (const char * e) {
116+ cerr << e << endl;
117+ }
114118
115119 case ' 0' :
116120 break ;
@@ -136,7 +140,7 @@ void Program::printGraphTypeSelect() {
136140 cout << " 1. Graf nieskierowany" << endl;
137141 cout << " 2. Graf skierowany" << endl;
138142 cout << " 0. Wyjscie" << endl;
139- cout << " Podaj opcje:" ;
143+ cout << " Podaj opcje: " ;
140144}
141145
142146void Program::printGraphMenu () {
@@ -156,26 +160,45 @@ void Program::printGraphMenu() {
156160 cout << availableAlgorithms;
157161
158162 cout << " 0. Wyjscie" << endl;
159- cout << " Podaj opcje:" ;
163+ cout << " Podaj opcje: " ;
160164}
161165
162166void Program::runAlgorithm (char index) {
163- int arg1;
167+ string arg1s;
168+ char arg1;
164169 int arg2;
170+ int arg3;
171+
165172 if (graph->getNumberOfAvailableAlgorithms () > index - 1 ) {
166173 cout << " Podaj argument 1: " ;
167- while (!(cin >> arg1)) {
168- cin.clear ();
169- cin.ignore (numeric_limits<streamsize>::max (), ' \n ' );
174+ cin >> arg1s;
175+ while (arg1s != " l" || arg1s != " L" || arg1s != " m" || arg1s != " M" ) {
170176 cerr << " Bledna wartosc! Podaj argument 1: " ;
177+ cin >> arg1s;
171178 }
179+
180+ if (arg1s == " m" || arg1s == " M" )
181+ arg1 = 0 ; // reprezentacja macierzowa
182+ else if (arg1s == " l" || arg1s == " L" )
183+ arg1 = 1 ; // reprezentacja listowa
184+ else
185+ throw " Nieznany blad!" ; // should never be thrown
186+
172187 cout << " Podaj argument 2: " ;
173188 while (!(cin >> arg2)) {
174189 cin.clear ();
175190 cin.ignore (numeric_limits<streamsize>::max (), ' \n ' );
176191 cerr << " Bledna wartosc! Podaj argument 2: " ;
177192 }
178- graph->runAlgorithm (index, arg1, arg2);
193+
194+ cout << " Podaj argument 3: " ;
195+ while (!(cin >> arg3)) {
196+ cin.clear ();
197+ cin.ignore (numeric_limits<streamsize>::max (), ' \n ' );
198+ cerr << " Bledna wartosc! Podaj argument 3: " ;
199+ }
200+
201+ graph->runAlgorithm (index, arg1, arg2, 0 );
179202 } else {
180203 cerr << " Nie ma takiej opcji, wybierz jeszcze raz." << endl;
181204 }
0 commit comments