
Untitled
By: a guest on
Jun 30th, 2012 | syntax:
None | size: 0.87 KB | hits: 14 | expires: Never
Powtórzenie wiadomości programowanie obiektowe.
#include <iostream>
#include <string>
using namespace std;
class Towar
{
private:
int cena;
string nazwa;
double waga;
static int lproduktow;
public:
Towar()
{
cout<<"Tworze obiekt"<<endl;
}
Towar (Towar &inne)
{
this->cena = inne.cena;
this->waga = inne.waga;
this->nazwa = inne.nazwa;
lproduktow++;
}
Towar (int cena, string nazwa, double waga)
{
this->cena=cena;
this->nazwa=nazwa;
this->waga=waga;
lproduktow++;
}
static void ile_jest_produktow();
void wyswietl()
{
cout<<"Wyswietlam towar"<<endl;
}
Towar::~Towar()
{
lproduktow--;
}
};
int Towar::lproduktow = 0;
void Towar::ile_jest_produktow()
{
cout<<"mamy: "<<lproduktow<<"produkty"<<endl;
}
int main()
{
Towar but(15,"but",15);
Towar but2(but);
Towar::ile_jest_produktow();
}