#include #include #include #include using namespace std; class Set { private: string nazwa1; string nazwa2; unsigned punkty1; unsigned punkty2; unsigned limit; // ile punktow potrzeba, aby wygrac set public: Set(string, string, unsigned); void drukuj_wynik() const; void zdobycie_punktu(bool); // true - dla pierwszej druzyny, false - dla drugiej druzyny bool zwyciezca(string&) const; }; Set::Set (string m_nazwa1, string m_nazwa2, unsigned m_limit) { nazwa1 = m_nazwa1; nazwa2 = m_nazwa2; limit = m_limit; punkty1 = 0; punkty2 = 0; } void Set::drukuj_wynik() const { cout<< nazwa1 <<" - "<< nazwa2<< "\t" << punkty1 << ":" << punkty2 << endl; } void Set::zdobycie_punktu(bool druzyna) { if(druzyna) ++punkty1; else ++punkty2; } bool Set::zwyciezca(string& nazwa) const { if(punkty1 < limit && punkty2 < limit) return false; // brak zwyciezcy if(punkty1 >= limit && (punkty1 - punkty2) > 1) { nazwa = nazwa1; return true; } if(punkty2 >= limit && (punkty2 - punkty1) > 1) { nazwa = nazwa2; return true; } return false; } int main() { srand(static_cast(time(nullptr))); Set nowy_set("Brazylia", "Francja", 25); string druzyna; bool los; while(!nowy_set.zwyciezca(druzyna)) { los = rand() % 2; nowy_set.zdobycie_punktu(los); nowy_set.drukuj_wynik(); getch(); } cout << "Zwyciezca seta jest " << druzyna << endl; return 0; }