Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <map>
- using namespace std;
- class Towar
- {
- public:
- const string Nazwa;
- Towar(string nazwa) :Nazwa(nazwa)
- {
- }
- virtual ~Towar()
- {
- }
- virtual void wyswietlParametry() const = 0;
- string getName() const
- {
- return Nazwa;
- }
- };
- class Komputer :public Towar
- {
- public:
- int procesor;
- Komputer(string nazwa, int procesor) :Towar(nazwa), procesor(procesor)
- {
- cout << "Komputer " << nazwa << endl;
- }
- virtual ~Komputer()
- {
- }
- virtual void wyswietlParametry() const
- {
- cout << "Komputer " << getName() << " procesor " << procesor << " rdzeni" << endl;
- }
- };
- class Buty : public Towar
- {
- public:
- int rozmiar;
- Buty(string nazwa, int size) :Towar(nazwa), rozmiar(size)
- {
- cout << "Buty " << nazwa << endl;
- }
- virtual ~Buty()
- {
- }
- virtual void wyswietlParametry() const
- {
- cout << "Buty " << getName() << " maja rozmiar " << rozmiar << endl;
- }
- };
- class Magazyn
- {
- map <int, Towar*> mag;
- public:
- void dodaj(int nr, Towar* a)
- {
- int i = 0;
- mag.insert(std::pair<int,Towar*>(i,a));
- i = +1;
- }
- void wyszukaj(int k)
- {
- //map<int, Towar*> ::iterator it;
- mag.find(k);
- // nie wiem jak wypisac ten element
- }
- void wypisz()
- {
- map<int, Towar*>::iterator it = mag.begin();
- for (;it!=mag.end();++it)
- {
- cout << it->first << " " << it->second << endl;
- // nie wiem jak wypisac zawartosc mapy
- }
- }
- void wyczysc()
- {
- mag.clear();
- }
- };
- int main()
- {
- Komputer *k1=new Komputer("atari", 1);
- k1->wyswietlParametry();
- Buty *b1 = new Buty("nike", 41);
- b1->wyswietlParametry();
- Magazyn m1;
- int iter;
- for(iter=0;iter<10;iter++)
- {
- m1.dodaj(iter, k1);
- m1.dodaj(iter, b1);
- }
- m1.wypisz();
- m1.wyszukaj(1);
- delete k1;
- delete b1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement