Professional Documents
Culture Documents
#include <string>
#include <vector>
#include <limits>
class trening {
public:
int dystans;
float czas;
trening() {};
trening(float d, float c);
void dodajTrening() {
// cout << "Oto twoje tempo: " <<tempo<< " m na km" << endl;
// cout << "Oto twoja prędkość: " <<predkosc<<" km/h" << endl;
}
void wyswietlWyniki()
{
cout<<"Oto twoje tempo: " << czas/dystans <<" min/km" << endl;
cout << "Oto twoja predkosc: " << dystans/(czas/60)<<" km/h" << endl;
}
};
class Player {
public:
string imie;
string nazwisko;
vector<trening> treningi;
void input() {
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Podaj Imie: " << endl;
getline(cin, imie);
cout << "Podaj nazwisko: " << endl;
getline(cin, nazwisko);
}
void wyswietl() {
cout << "Imie: " << imie << endl;
cout << "Nazwisko: " << nazwisko << endl;
}
void wyswietlWyniki(){
if (treningi.empty()) {
cout << "Najpierw dodaj cwiczenia" << endl;
}
else {
for (auto e : treningi)
{
e.wyswietlWyniki();
cout << "--------\n";
cout << e.czas<<endl;
}
}
}
void dodajTrening() {
int d;
float c;
cout << "Podaj przebyty dystans: " << endl;
cin >> d;
cout << "Podaj czas (minuty) w ktorym pokonales dany dystans: " << endl;
cin >> c;
treningi.push_back(trening(d, c));
}
};
int main() {
vector<Player> lista;
while (true) {
int wybor;
int index = 1;
cout << "---------\n";
for (auto player : lista) {
cout << "Player #" << index << ":" << endl;
player.wyswietl();
cout << "------------\n" << endl;
index++;
}
cout << "1. Dodaj Biegacza: " << endl;
cout << "2. Wyswietl Wyniki: " << endl;
cout << "3. Usun Obiekt: " << endl;
cout << "4. Kopiuj Obiekt: " << endl;
cout << "5. Dodaj trening: " << endl;
cout << "6 .Edytuj Biegacza" << endl;
cout << "Wybierz opcje: " << endl;
cin >> wybor;
switch (wybor) {
case 1: {
string i, n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Podaj Imie: " << endl;
getline(cin, i);
cout << "Podaj nazwisko: " << endl;
getline(cin, n);
lista.push_back(Player(i,n));
break;
}
case 2: {
int index = 1;
cout << "---ddddd------\n";
for (auto player : lista) {
cout << "Player #" << index << ":" << endl;
player.wyswietl();
cout << "---xx---\n";
player.wyswietlWyniki();
index++;
break;
}
case 3: {
if (lista.empty()) {
cout << "Lista jest pusta." << endl;
break;
}
int numer;
cout << "Podaj numer biegacza do usuniecia: " << endl;
cin >> numer;
numer--;
if (numer >= 0 && numer < lista.size()) {
lista.erase(lista.begin() + numer);
cout << "Gracz #" << numer + 1 << " Zostal usuniety" << endl;
}
else {
cout << "Nieprawidlowy numer biegacza." << endl;
}
break;
}
case 4: {
int i;
cout << "Podaj numer biegacza do skopiowania: " << endl;
cin >> i;
--i;
if (i >= 0 && i < lista.size()) {
lista.push_back(lista[i]);
}
else {
cout << "Nieprawidlowy numer." << endl;
}
break;
}
case 5: {
index = 1;
for (auto player : lista) {
cout << "Player #" << index << ":" << endl;
player.wyswietl();
cout << "------------\n" << endl;
index++;
}
if (lista.empty()) {
cout << "Lista jest pusta. Najpierw dodaj biegacza." << endl;
break;
}
int numer;
cout << "Podaj numer biegacza, ktoremu chcesz dodac trening: " << endl;
cin >> numer;
numer--;
if (numer >= 0 && numer < lista.size()) {
lista.at(numer).dodajTrening();
}
else {
cout << "Nieprawidlowy numer biegacza." << endl;
}
break;
}
case 6:
{
cout << "---------------" << endl;
int numer;
cout << "Podaj numer biegacza do edycji: " << endl;
cin >> numer;
numer--;
lista.erase(lista.begin() + numer);
string i, n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Podaj Imie: " << endl;
getline(cin, i);
cout << "Podaj nazwisko: " << endl;
getline(cin, n);
lista.push_back(Player(i, n));
cout << "Gracz #" << numer + 1 << " Zostal edytowany" << endl;
}
else {
cout << "Nieprawidlowy numer biegacza." << endl;
}
break;
}
}
}
return 0;
}
trening::trening(float d, float c)
{
czas = c;
dystans = d;
}
Player::Player(string i, string n)
{
imie = i;
nazwisko = n;
}