Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //header
- #pragma once
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <string>
- using namespace std;
- class Komputer {
- static int id;
- static int licznik;
- int iid;
- string nazwa;
- static const int cena = 2000;
- public:
- string typ = "Komputer";
- Komputer();
- Komputer(string);
- Komputer(const Komputer&);
- ~Komputer();
- int get_id();
- void wypisz();
- static int getLicznik()
- {
- return licznik;
- }
- };
- class Laptop
- :public Komputer
- {
- static const int cena = 5000;
- string nazwa;
- public:
- string typ = "Laptop";
- Laptop();
- Laptop(string);
- Laptop(const Laptop&);
- ~Laptop();
- void wypisz();
- };
- class Serwer
- :public Komputer
- {
- static const int cena = 7000;
- string nazwa;
- public:
- string typ = "Serwer";
- Serwer();
- Serwer(string);
- Serwer(const Serwer&);
- ~Serwer();
- void wypisz();
- };
- //Komputer
- #include "Header.h"
- int Komputer::licznik = 0;
- Komputer::Komputer()
- {
- cout << "domyslny konstruktor komputer" << endl;
- iid = ++licznik;
- nazwa = "domyslny";
- }
- Komputer::Komputer(const Komputer& kKomputer)
- {
- cout << "kopiujacy konstruktor komputer" << endl;
- iid = kKomputer.iid;
- nazwa = kKomputer.nazwa;
- }
- Komputer::Komputer(string nowa_nazwa)
- {
- cout << "parametryczny konstruktor komputer" << endl;
- iid = ++licznik;
- nazwa = nowa_nazwa;
- }
- void Komputer::wypisz()
- {
- cout << "Typ: " << typ << endl;
- cout << "nazwa: " << nazwa << endl;
- cout << "id: " << iid << endl;
- cout << "cena: " << cena << endl;
- }
- int Komputer::get_id()
- {
- return iid;
- }
- Komputer::~Komputer()
- {
- cout << "destruktor komputer" << endl;
- licznik--;
- }
- //Laptop
- #include "Header.h"
- Laptop::Laptop()
- {
- cout << "domyslny konstruktor laptop" << endl;
- nazwa = "domyslny";
- }
- Laptop::Laptop(string nowa_nazwa)
- {
- cout << "param konstruktor laptop" << endl;
- nazwa = nowa_nazwa;
- }
- Laptop::Laptop(const Laptop& kLaptop)
- {
- cout << "kop konstruktor laptop" << endl;
- nazwa = kLaptop.nazwa;
- }
- void Laptop::wypisz()
- {
- cout << "Typ: " << typ << endl;
- cout << "nazwa: " << nazwa << endl;
- cout << "id: " << Komputer::get_id() << endl;
- cout << "cena: " << cena << endl;
- }
- Laptop::~Laptop()
- {
- cout << "destruktor laptop" << endl;
- }
- //Serwer
- #include "Header.h"
- Serwer::Serwer()
- {
- cout << "domyslny konstruktor serwer" << endl;
- nazwa = "domyslny";
- }
- Serwer::Serwer(string nowa_nazwa)
- {
- cout << "param konstruktor serwer" << endl;
- nazwa = nowa_nazwa;
- }
- Serwer::Serwer(const Serwer& kSerwer)
- {
- cout << "kop konstruktor serwer" << endl;
- nazwa = kSerwer.nazwa;
- }
- void Serwer::wypisz()
- {
- {
- cout << "Typ: " << typ << endl;
- cout << "nazwa: " << nazwa << endl;
- cout << "id: " << Komputer::get_id() << endl;
- cout << "cena: " << cena << endl;
- }
- }
- Serwer::~Serwer()
- {
- cout << "destruktor serwer" << endl;
- }
- //main
- #include "Header.h"
- int main()
- {
- {
- Komputer domyslny_komputer;
- Laptop domyslny_laptop;
- Laptop param_laptop("nowy");
- Serwer domyslny_serwer;
- Serwer kop_serwer(domyslny_serwer);
- domyslny_komputer.wypisz();
- domyslny_laptop.wypisz();
- param_laptop.wypisz();
- domyslny_serwer.wypisz();
- kop_serwer.wypisz();
- cout <<"Licznik: "<< Komputer::getLicznik() << endl;
- }
- cout << "Licznik: " << Komputer::getLicznik() << endl;
- Komputer *zespol[3];
- zespol[0] = new Komputer;
- zespol[1] = new Laptop;
- zespol[2] = new Serwer;
- for (int i = 0; i < 3; i++)
- {
- zespol[i]->wypisz();
- }
- for (int i = 0; i < 3; i++)
- {
- delete zespol[i];
- }
- cout << "Licznik: " << Komputer::getLicznik() << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement