Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 30th, 2012  |  syntax: None  |  size: 0.87 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Powtórzenie wiadomości programowanie obiektowe.
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. class Towar
  9. {
  10. private:
  11. int cena;
  12. string nazwa;
  13. double waga;
  14. static int lproduktow;
  15.  
  16. public:
  17.         Towar()
  18.         {
  19.                 cout<<"Tworze obiekt"<<endl;
  20.         }
  21.         Towar (Towar &inne)
  22.         {
  23.                 this->cena = inne.cena;
  24.                 this->waga = inne.waga;
  25.                 this->nazwa = inne.nazwa;
  26.                 lproduktow++;
  27.         }
  28.         Towar (int cena, string nazwa, double waga)
  29.         {
  30.                 this->cena=cena;
  31.                 this->nazwa=nazwa;
  32.                 this->waga=waga;
  33.                 lproduktow++;
  34.         }
  35.         static void ile_jest_produktow();
  36.  
  37.         void wyswietl()
  38.         {
  39.                 cout<<"Wyswietlam towar"<<endl;
  40.         }
  41.         Towar::~Towar()
  42.         {
  43.                 lproduktow--;
  44.         }
  45. };
  46. int Towar::lproduktow = 0;
  47. void Towar::ile_jest_produktow()
  48. {
  49.         cout<<"mamy: "<<lproduktow<<"produkty"<<endl;
  50. }
  51. int main()
  52. {
  53.         Towar but(15,"but",15);
  54.  
  55.         Towar but2(but);
  56.         Towar::ile_jest_produktow();
  57. }