Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Towar
  4. {
  5. private:
  6. string nazwa;
  7. string kod;
  8. double cena;
  9. double ilosc;
  10. public:
  11. // to jest konstruktor bo ma te sama nazwe co klasa !!!!
  12. Towar(string _nazwa, string _kod, double _cena, double _ilosc)
  13. {
  14. nazwa = _nazwa;
  15. kod = _kod;
  16. cena = _cena;
  17. ilosc = _ilosc;
  18. }
  19. void Wyswietl()
  20. {
  21. cout<<endl<<"Nazwa: "<<nazwa;
  22. cout<<endl<<"Kod: "<<kod;
  23. cout<<endl<<"Cena: "<<cena;
  24. cout<<endl<<"Ilosc: "<<ilosc;
  25. }
  26. };
  27. int main()
  28. {
  29. // tu automatycznie wywola sie konstruktor, w nawiasie musimy podac tyle
  30. // parametrow ile bylo parametrow w konstruktorze
  31. Towar t1("Pilka","P1",10,1);
  32. t1.Wyswietl();
  33. Towar t2("Buty","B1",11,2);
  34. t2.Wyswietl();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement