Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <conio.h>
- #include <ctime>
- using namespace std;
- class CSet
- {
- string home;
- string away;
- unsigned home_result;
- unsigned away_result;
- bool set_trwa;
- public:
- CSet(string, string);
- void start();
- void komunikat();
- void losuj_punkt();
- };
- CSet::CSet(string a, string b) : home(a), away(b), home_result(0), away_result(0), set_trwa(true) {}
- void CSet::losuj_punkt()
- {
- srand(static_cast<unsigned>(time(nullptr)));
- if(rand() % 2 == 0)
- ++home_result;
- else
- ++away_result;
- if(home_result >= 25 || away_result >= 25)
- {
- if(home_result - away_result >= 2 || away_result - home_result >= 2)
- {
- set_trwa = false;
- return;
- }
- }
- }
- void CSet::komunikat()
- {
- cout << home << '\t' << home_result << ':' << away_result << '\t' << away << endl;
- if(!set_trwa)
- {
- if(home_result > away_result)
- cout << "Druzyna " << home << " wygrywa set\n";
- else
- cout << "Druzyna " << away << " wygrywa set\n";
- }
- }
- void CSet::start()
- {
- while(set_trwa)
- {
- losuj_punkt();
- komunikat();
- getch();
- }
- }
- int main()
- {
- cout << "Podaj nazwy dwoch grajacych druzyn:\n";
- cout << "\tdruzyna gospodarzy: ";
- string a, b;
- getline(cin, a);
- cout << "\tdruzyna gosci: ";
- getline(cin, b);
- CSet nowy_set(a, b);
- nowy_set.start();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement