Skip to content
This repository was archived by the owner on May 27, 2019. It is now read-only.

Commit 3e5b6fa

Browse files
committed
Merge branch 'fix-args-again' into development
2 parents f3adce4 + a03f94f commit 3e5b6fa

6 files changed

Lines changed: 38 additions & 15 deletions

File tree

DirectedGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ DirectedGraph::DirectedGraph() : Graph("Graf skierowany", 1) {}
1515
std::string DirectedGraph::getAvailableAlgorithms() {
1616
std::string output = "";
1717

18-
output += "6. Algorytm Dijkstry (SP) [arg1 <- wierzch. pocz.; arg2 <- wierzch. konc.]\n";
18+
output += "6. Algorytm Dijkstry (SP) [arg1 <- rodzaj reprezentacji (m - macierz, l - lista); arg2 <- wierzch. pocz.; arg3 <- wierzch. konc.]\n";
1919

2020
return output;
2121
}
@@ -74,7 +74,7 @@ void DirectedGraph::generate(int numberOfVertices, int density) {
7474

7575
}
7676

77-
void DirectedGraph::runAlgorithm(int index, int arg1, int arg2) {
77+
void DirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
7878

7979
}
8080

DirectedGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DirectedGraph : public Graph {
1616

1717
void generate(int numberOfVertices, int density) override;
1818

19-
void runAlgorithm(int index, int arg1, int arg2) override;
19+
void runAlgorithm(char index, char arg1, int arg2, int arg3) override;
2020

2121
void test() override;
2222

Graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Graph {
4545

4646
virtual void generate(int numberOfVertices, int density)= 0;
4747

48-
virtual void runAlgorithm(int index, int arg1, int arg2)= 0;
48+
virtual void runAlgorithm(char index, char arg1, int arg2, int arg3)= 0;
4949

5050
virtual void test()= 0;
5151

Program.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

142146
void 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

162166
void 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
}

UndirectedGraph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ UndirectedGraph::UndirectedGraph() : Graph("Graf nieskierowany", 1) {}
1414
std::string UndirectedGraph::getAvailableAlgorithms() {
1515
std::string output = "";
1616

17-
output += "6. Algorytm Prima (MST) [arg1 <- 0; arg2 <- 0]\n";
17+
output += "6. Algorytm Prima (MST) [arg1 <- rodzaj reprezentacji (m - macierz, l - lista); arg2 <- 0; arg3 <- 0]\n";
1818

1919
return output;
2020
}
@@ -74,7 +74,7 @@ void UndirectedGraph::generate(int numberOfVertices, int density) {
7474
}
7575
}
7676

77-
void UndirectedGraph::runAlgorithm(int index, int arg1, int arg2) {
77+
void UndirectedGraph::runAlgorithm(char index, char arg1, int arg2, int arg3) {
7878

7979
}
8080

UndirectedGraph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class UndirectedGraph : public Graph {
1616

1717
void generate(int numberOfVertices, int density) override;
1818

19-
void runAlgorithm(int index, int arg1, int arg2) override;
19+
void runAlgorithm(char index, char arg1, int arg2, int arg3) override;
2020

2121
void test() override;
2222

0 commit comments

Comments
 (0)