Professional Documents
Culture Documents
#include <vector>
class Trening {
public:
float dystans;
float czas;
float tempo;
float predkosc;
void wyswietl();
class Biegacz {
public:
string imie;
string nazwisko;
vector<Trening> treningi;
Biegacz();
};
int main() {
int wybor = 0;
vector<Biegacz> lista;
while (wybor != 4) {
cout << "1 - Biegacz" << endl;
cout << "2 - Dodaj treningi" << endl;
cout << "3 - Statystyki" << endl;
cout << "4 - Zakonczenie" << endl;
cin >> wybor;
switch (wybor) {
case 1: {
int wyybor = 0;
while (wyybor != 4) {
cout << "1 - Dodaj biegacza" << endl;
cout << "2 - Usun biegacza" << endl;
cout << "3 - Edytuj dane biegacza" << endl;
cout << "4 - Zakonczenie" << endl;
cin >> wyybor;
switch (wyybor) {
case 1: {
int liczbaBiegaczy;
cout << "Ile biegaczy chcesz dodac? ";
cin >> liczbaBiegaczy;
for (int i = 0; i < liczbaBiegaczy; ++i) {
lista.push_back(Biegacz());
float dystans, czas;
cout << "Podaj dystans w kilometrach: ";
cin >> dystans;
cout << "Podaj czas w minutach: ";
cin >> czas;
lista.back().dodaj_Trening(dystans, czas);
}
cout << "Dodano " << liczbaBiegaczy << " biegaczy do listy" <<
endl;
break;
}
case 2: {
cout << "Podaj numer biegacza, ktorego chcesz usunac: ";
int nr_bieg;
cin >> nr_bieg;
if (nr_bieg >= 1 && nr_bieg <= lista.size()) {
lista.erase(lista.begin() + nr_bieg - 1);
cout << "Usunieto biegacza z listy" << endl;
}
break;
}
case 3: {
cout << "Podaj numer biegacza, ktorego dane chcesz edytowac: ";
int nr_bieg;
cin >> nr_bieg;
if (nr_bieg >= 1 && nr_bieg <= lista.size()) {
cout << "Nowe imie: ";
cin >> lista[nr_bieg - 1].imie;
cout << "Nowe nazwisko: ";
cin >> lista[nr_bieg - 1].nazwisko;
cout << "Dane biegacza zostaly zaktualizowane" << endl;
}
case 4: {
cout << "Powro t do Menu!" << endl;
break;
}
}
}
break;
}
case 2: {
cout << "Podaj numer biegacza, do ktorego chcesz dodac trening: ";
int nr_bieg;
cin >> nr_bieg;
if (nr_bieg >= 1 && nr_bieg <= lista.size()) {
float dystans, czas;
cout << "Podaj dystans w kilometrach: ";
cin >> dystans;
cout << "Podaj czas w minutach: ";
cin >> czas;
lista[nr_bieg - 1].dodaj_Trening(dystans, czas);
}
break;
}
case 3: {
if (!lista.empty()) {
cout << "Statystyki biegaczy:" << endl;
Biegacz* najwyzsze_tempo = &lista[0];
for ( auto biegacz : lista) {
for ( auto trening : biegacz.treningi) {
if (trening.tempo > najwyzsze_tempo->treningi.back().tempo) {
najwyzsze_tempo = &biegacz;
}
}
}
cout << "Najwyzsze tempo: " << najwyzsze_tempo->imie << " " <<
najwyzsze_tempo->nazwisko << " - " << najwyzsze_tempo->treningi.back().tempo << "
[min/km]" << endl;
system("cls");
}
}
}
return 0;
}
void Trening::wyswietl() {
cout << "--------------------------------" << endl;
cout << "Dystans: " << dystans << endl;
cout << "Czas: " << czas << endl;
cout << "Tempo: " << tempo << " [min/km]" << endl;
cout << "Predkosc: " << predkosc << " [km/h]" << endl;
}
Biegacz::Biegacz() {
cout << "Podaj imie: " << endl;
cin >> imie;
cout << "Podaj nazwisko: " << endl;
cin >> nazwisko;
}