Advertisement
MeehoweCK

Untitled

Dec 11th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. class Set
  9. {
  10. private:
  11.     string nazwa1;
  12.     string nazwa2;
  13.     unsigned punkty1;
  14.     unsigned punkty2;
  15.     unsigned limit;     // ile punktow potrzeba, aby wygrac set
  16. public:
  17.     Set(string, string, unsigned);
  18.     void drukuj_wynik() const;
  19.     void zdobycie_punktu(bool);     // true - dla pierwszej drużyny, false - dla drugiej drużyny
  20.     bool zwyciezca(string&) const;
  21. };
  22.  
  23. Set::Set (string m_nazwa1, string m_nazwa2, unsigned m_limit)
  24. {
  25.     nazwa1 = m_nazwa1;
  26.     nazwa2 = m_nazwa2;
  27.     limit = m_limit;
  28.     punkty1 = 0;
  29.     punkty2 = 0;
  30. }
  31.  
  32. void Set::drukuj_wynik() const
  33. {
  34.     cout<< nazwa1 <<" - "<< nazwa2<< "\t" << punkty1 << ":" << punkty2 << endl;
  35. }
  36.  
  37. void Set::zdobycie_punktu(bool druzyna)
  38. {
  39.     if(druzyna)
  40.         ++punkty1;
  41.     else
  42.         ++punkty2;
  43. }
  44.  
  45. bool Set::zwyciezca(string& nazwa) const
  46. {
  47.     if(punkty1 < limit && punkty2 < limit) return false;        // brak zwyciezcy
  48.     if(punkty1 >= limit && (punkty1 - punkty2) > 1)
  49.     {
  50.         nazwa = nazwa1;
  51.         return true;
  52.     }
  53.     if(punkty2 >= limit && (punkty2 - punkty1) > 1)
  54.     {
  55.         nazwa = nazwa2;
  56.         return true;
  57.     }
  58.     return false;
  59. }
  60.  
  61. int main()
  62. {
  63.     srand(static_cast<unsigned>(time(nullptr)));
  64.     Set nowy_set("Brazylia", "Francja", 25);
  65.     string druzyna;
  66.     bool los;
  67.     while(!nowy_set.zwyciezca(druzyna))
  68.     {
  69.         los = rand() % 2;
  70.         nowy_set.zdobycie_punktu(los);
  71.         nowy_set.drukuj_wynik();
  72.         getch();
  73.     }
  74.     cout << "Zwyciezca seta jest " << druzyna << endl;
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement