Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct Data_produkcji
- {
- int dzien, miesiac, rok;
- };
- struct Przedmiot
- {
- static int ilosc;
- int id;
- string nazwa;
- double cena;
- void wypisz();
- Data_produkcji dp;
- Przedmiot() { ; }
- Przedmiot(int _id, string _nazwa, double _cena, int _dzien, int _miesiac, int _rok) //KONSTRUKTOR to co sie wykonuje podczas tworzenia obiektu
- {
- ilosc++;
- id = _id;
- nazwa = _nazwa;
- cena = _cena;
- dp.dzien = _dzien;
- dp.miesiac = _miesiac;
- dp.rok = _rok;
- }
- ~Przedmiot() //DESTRYKTOR to co się wykonuje po usunięciu obiektu
- {
- ilosc--;
- }
- };
- int Przedmiot::ilosc = 0; //tak trzeba bo "static" i w sumie nie wiem czemu tak
- /*
- Przedmiot::~Przedmiot() //mozna też tak definicja destruktora i konstruktora
- {
- ilosc--;
- }
- */
- void Przedmiot::wypisz()
- {
- cout << "---- " << nazwa << " ----" << endl;
- cout << ilosc << endl;
- cout << id << endl;
- cout << cena << endl;
- cout << dp.dzien << endl;
- cout << dp.miesiac << endl;
- cout << dp.rok << endl;
- cout << "-----------" << endl;
- }
- int main()
- {
- Przedmiot p1(1, "myszka", 133, 01,01,2020);
- Przedmiot p2(2, "laptop", 2110, 01,02,1999);
- Przedmiot p3 = p2;
- p3.cena = 3000;
- p3.dp.rok = 2010;
- p3.id = 3;
- Przedmiot* p4 = &p3;
- p4->nazwa = "komputer";
- p4->id = 4;
- Przedmiot* p5 = new Przedmiot;
- *p5 = *p4;
- p5->id = 5;
- p5->nazwa = "ekran";
- p5->cena = 720;
- Przedmiot magazyn[5] = { p1,p2,p3,*p4,*p5 };
- for (int i = 0; i < 5; i++)
- {
- magazyn[i].wypisz();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement