wiktortokumpel

struktury i klasy wronson

Mar 15th, 2022
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Counter //Licznik do liczenia
  6. {
  7.     int counter;        //licznik
  8.     int dc;             //o ile zwiekszyć
  9.     int Id;
  10.     void reset() // resetowanie licznika
  11.     {
  12.      counter=0;
  13.      dc=1;
  14.     }
  15.     void show() //wyswietlanie licznika
  16.     {
  17.         cout<<"Stan licznika: "<<counter<<endl;
  18.     }
  19.     void add()// dodawawnie do licznika
  20.     {
  21.         counter+=dc;
  22.     }
  23.     void sub()// odejmowanie od licznika
  24.     {
  25.         counter -=dc;
  26.     }
  27.     void setCounter(int value)//ustawienie wartości
  28.     {
  29.      counter=value;
  30.     }
  31.     void setDc(int value) //usrawuenie przyrostu
  32.     {
  33.         dc=value;
  34.     }
  35.     void setID(int value) //usprawnienie jeżeli chodzi o numeracje liczników by odróźnić
  36.     {
  37.         Id=value;
  38.     }
  39. };
  40.  
  41. int main()
  42. {
  43.     Counter c1={10,1,1};
  44.     Counter c2={0,5,2};
  45.     c1.add();
  46.     c1.show();
  47.     c2.add();
  48.     c2.show();
  49.  
  50.  
  51.  
  52.  
  53.     return 0;
  54. }
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment