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

Commit fde5d58

Browse files
committed
Merge branch 'fix-args' into development
2 parents f4d29a4 + 6cede4d commit fde5d58

7 files changed

Lines changed: 41 additions & 44 deletions

File tree

DirectedGraph.cpp

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

14-
output += "5. Algorytm Dijkstry (SP)\n";
14+
output += "6. Algorytm Dijkstry (SP) [arg1 <- wierzch. pocz.; arg2 <- wierzch. konc.]\n";
1515

1616
return output;
1717
}
@@ -24,7 +24,7 @@ void DirectedGraph::generate(int numberOfVertices, int density) {
2424

2525
}
2626

27-
void DirectedGraph::runAlgorithm(int index) {
27+
void DirectedGraph::runAlgorithm(int index, int arg1, int arg2) {
2828

2929
}
3030

DirectedGraph.h

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

1919
void generate(int numberOfVertices, int density) override;
2020

21-
void runAlgorithm(int index) override;
21+
void runAlgorithm(int index, int arg1, int arg2) override;
2222

2323
void test() override;
2424

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)= 0;
48+
virtual void runAlgorithm(int index, int arg1, int arg2)= 0;
4949

5050
virtual void test()= 0;
5151

Program.cpp

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void Program::start() {
2020
int density;
2121
string matrix;
2222
string list;
23+
char index;
2324

2425
do {
2526
printGraphTypeSelect();
@@ -96,45 +97,16 @@ void Program::start() {
9697
cout << endl;
9798
break;
9899

99-
case '5': // algorytm 1
100-
if (graph->getNumberOfAvailableAlgorithms() > 0) {
101-
graph->runAlgorithm(1);
102-
} else {
103-
cout << "Nie ma takiej opcji, wybierz jeszcze raz." << endl;
104-
}
105-
break;
106-
107-
case '6': // algorytm 2
108-
if (graph->getNumberOfAvailableAlgorithms() > 1) {
109-
graph->runAlgorithm(2);
110-
} else {
111-
cout << "Nie ma takiej opcji, wybierz jeszcze raz." << endl;
112-
}
113-
break;
114-
115-
case '7': // algorytm 3
116-
if (graph->getNumberOfAvailableAlgorithms() > 2) {
117-
graph->runAlgorithm(3);
118-
} else {
119-
cout << "Nie ma takiej opcji, wybierz jeszcze raz." << endl;
120-
}
121-
break;
122-
123-
case '8': // algorytm 4
124-
if (graph->getNumberOfAvailableAlgorithms() > 3) {
125-
graph->runAlgorithm(4);
126-
} else {
127-
cout << "Nie ma takiej opcji, wybierz jeszcze raz." << endl;
128-
}
100+
case '5':
101+
graph->test();
129102
break;
130103

131-
case '9': // algorytm 5
132-
if (graph->getNumberOfAvailableAlgorithms() > 4) {
133-
graph->runAlgorithm(5);
134-
} else {
135-
cout << "Nie ma takiej opcji, wybierz jeszcze raz." << endl;
136-
}
137-
break;
104+
case '6':
105+
case '7':
106+
case '8':
107+
case '9':
108+
index = option2 - 53;
109+
runAlgorithm(index);
138110

139111
case '0':
140112
break;
@@ -172,10 +144,33 @@ void Program::printGraphMenu() {
172144
cout << "2. Generuj losowo" << endl;
173145
cout << "3. Wyswietl graf jako macierz" << endl;
174146
cout << "4. Wyswietl graf jako lista" << endl;
147+
cout << "5. Wykonaj testy" << endl;
175148

176149
string availableAlgorithms = graph->getAvailableAlgorithms();
177150
cout << availableAlgorithms;
178151

179152
cout << "0. Wyjscie" << endl;
180153
cout << "Podaj opcje:";
181154
}
155+
156+
void Program::runAlgorithm(char index) {
157+
int arg1;
158+
int arg2;
159+
if (graph->getNumberOfAvailableAlgorithms() > index - 1) {
160+
cout<<"Podaj argument 1: ";
161+
while (!(cin >> arg1)) {
162+
cin.clear();
163+
cin.ignore(numeric_limits<streamsize>::max(), '\n');
164+
cout << "Bledna wartosc! Podaj argument 1: ";
165+
}
166+
cout<<"Podaj argument 2: ";
167+
while (!(cin >> arg2)) {
168+
cin.clear();
169+
cin.ignore(numeric_limits<streamsize>::max(), '\n');
170+
cout << "Bledna wartosc! Podaj argument 2: ";
171+
}
172+
graph->runAlgorithm(index, arg1, arg2);
173+
} else {
174+
cout << "Nie ma takiej opcji, wybierz jeszcze raz." << endl;
175+
}
176+
}

Program.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Program {
2020
void printGraphTypeSelect();
2121

2222
void printGraphMenu();
23+
24+
void runAlgorithm(char index);
2325
};
2426

2527

UndirectedGraph.cpp

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

14-
output += "5. Algorytm Prima (MST)\n";
14+
output += "6. Algorytm Prima (MST) [arg1 <- 0; arg2 <- 0]\n";
1515

1616
return output;
1717
}
@@ -24,7 +24,7 @@ void UndirectedGraph::generate(int numberOfVertices, int density) {
2424

2525
}
2626

27-
void UndirectedGraph::runAlgorithm(int index) {
27+
void UndirectedGraph::runAlgorithm(int index, int arg1, int arg2) {
2828

2929
}
3030

UndirectedGraph.h

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

1919
void generate(int numberOfVertices, int density) override;
2020

21-
void runAlgorithm(int index) override;
21+
void runAlgorithm(int index, int arg1, int arg2) override;
2222

2323
void test() override;
2424

0 commit comments

Comments
 (0)