You are on page 1of 4

#include <iostream>

#include <vector>

using namespace std;

class Trening {
public:
float dystans;
float czas;
float tempo;
float predkosc;
void wyswietl();

Trening(float dystans, float czas);


};

class Biegacz {
public:
string imie;
string nazwisko;
vector<Trening> treningi;

void dodaj_Trening(float dystans, float czas);

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;

cout << "Czy chcesz edytowac trening tego biegacza? (Tak -


1, Nie - 0): ";
int wybor_treningu;
cin >> wybor_treningu;
if (wybor_treningu == 1) {
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);
}
}

}
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;

Biegacz* najwieksza_predkosc = &lista[0];


for ( auto biegacz : lista) {
for ( auto trening : biegacz.treningi) {
if (trening.predkosc > najwieksza_predkosc-
>treningi.back().predkosc) {
najwieksza_predkosc = &biegacz;
}
}
}
cout << "Najwieksza predkosc: " << najwieksza_predkosc->imie << " " <<
najwieksza_predkosc->nazwisko << " - " << najwieksza_predkosc-
>treningi.back().predkosc << " [km/h]" << endl;

Biegacz* najkrotszy_czas = &lista[0];


for ( auto biegacz : lista) {
for ( auto trening : biegacz.treningi) {
if (trening.czas < najkrotszy_czas->treningi.back().czas) {
najkrotszy_czas = &biegacz;
}
}
}
cout << "Najkrotszy czas: " << najkrotszy_czas->imie << " " <<
najkrotszy_czas->nazwisko << " - " << najkrotszy_czas->treningi.back().czas << "
[min]" << endl;

Biegacz* najdluzszy_dystans = &lista[0];


for ( auto biegacz : lista) {
for ( auto trening : biegacz.treningi) {
if (trening.dystans > najdluzszy_dystans-
>treningi.back().dystans) {
najdluzszy_dystans = &biegacz;
}
}
}
cout << "Najdluzszy dystans: " << najdluzszy_dystans->imie << " " <<
najdluzszy_dystans->nazwisko << " - " << najdluzszy_dystans-
>treningi.back().dystans << " [km]" << endl;
}
else {
cout << "Lista biegaczy jest pusta!" << endl;
}
break;
}
case 4: {
cout << "Koniec!!" << endl;
break;
}
default: {

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;
}

Trening::Trening(float dystans, float czas) {


dystans = dystans;
czas = czas;
tempo = czas / dystans;
predkosc = dystans / (czas / 60);
}

Biegacz::Biegacz() {
cout << "Podaj imie: " << endl;
cin >> imie;
cout << "Podaj nazwisko: " << endl;
cin >> nazwisko;
}

void Biegacz::dodaj_Trening(float dystans, float czas) {


Trening nowy_trening(dystans, czas);
treningi.push_back(nowy_trening);
cout << "Dodano nowy trening dla biegacza" << endl;

You might also like