Advertisement
MeehoweCK

Untitled

Nov 12th, 2020
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <conio.h>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. class CSet
  9. {
  10.     string home;
  11.     string away;
  12.     unsigned home_result;
  13.     unsigned away_result;
  14.     bool set_trwa;
  15. public:
  16.     CSet(string, string);
  17.     void start();
  18.     void komunikat();
  19.     void losuj_punkt();
  20. };
  21.  
  22. CSet::CSet(string a, string b) : home(a), away(b), home_result(0), away_result(0), set_trwa(true) {}
  23.  
  24. void CSet::losuj_punkt()
  25. {
  26.     srand(static_cast<unsigned>(time(nullptr)));
  27.     if(rand() % 2 == 0)
  28.         ++home_result;
  29.     else
  30.         ++away_result;
  31.     if(home_result >= 25 || away_result >= 25)
  32.     {
  33.         if(home_result - away_result >= 2 || away_result - home_result >= 2)
  34.         {
  35.             set_trwa = false;
  36.             return;
  37.         }
  38.     }
  39. }
  40.  
  41. void CSet::komunikat()
  42. {
  43.     cout << home << '\t' << home_result << ':' << away_result << '\t' << away << endl;
  44.     if(!set_trwa)
  45.     {
  46.         if(home_result > away_result)
  47.             cout << "Druzyna " << home << " wygrywa set\n";
  48.         else
  49.             cout << "Druzyna " << away << " wygrywa set\n";
  50.     }
  51. }
  52.  
  53. void CSet::start()
  54. {
  55.     while(set_trwa)
  56.     {
  57.         losuj_punkt();
  58.         komunikat();
  59.         getch();
  60.     }
  61. }
  62.  
  63. int main()
  64. {
  65.     cout << "Podaj nazwy dwoch grajacych druzyn:\n";
  66.     cout << "\tdruzyna gospodarzy: ";
  67.     string a, b;
  68.     getline(cin, a);
  69.     cout << "\tdruzyna gosci: ";
  70.     getline(cin, b);
  71.  
  72.     CSet nowy_set(a, b);
  73.     nowy_set.start();
  74.  
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement