Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. using namespace std;
  6.  
  7. class Towar
  8. {
  9. public:
  10. const string Nazwa;
  11.  
  12. Towar(string nazwa) :Nazwa(nazwa)
  13. {
  14. }
  15.  
  16. virtual ~Towar()
  17. {
  18. }
  19.  
  20. virtual void wyswietlParametry() const = 0;
  21.  
  22. string getName() const
  23. {
  24. return Nazwa;
  25. }
  26. };
  27.  
  28. class Komputer :public Towar
  29. {
  30. public:
  31. int procesor;
  32. Komputer(string nazwa, int procesor) :Towar(nazwa), procesor(procesor)
  33. {
  34. cout << "Komputer " << nazwa << endl;
  35. }
  36.  
  37. virtual ~Komputer()
  38. {
  39.  
  40. }
  41.  
  42. virtual void wyswietlParametry() const
  43. {
  44. cout << "Komputer " << getName() << " procesor " << procesor << " rdzeni" << endl;
  45. }
  46. };
  47.  
  48. class Buty : public Towar
  49. {
  50. public:
  51. int rozmiar;
  52. Buty(string nazwa, int size) :Towar(nazwa), rozmiar(size)
  53. {
  54. cout << "Buty " << nazwa << endl;
  55. }
  56.  
  57. virtual ~Buty()
  58. {
  59.  
  60. }
  61.  
  62. virtual void wyswietlParametry() const
  63. {
  64. cout << "Buty " << getName() << " maja rozmiar " << rozmiar << endl;
  65. }
  66. };
  67.  
  68. class Magazyn
  69. {
  70. map <int, Towar*> mag;
  71. public:
  72. void dodaj(int nr, Towar* a)
  73. {
  74. int i = 0;
  75. mag.insert(std::pair<int,Towar*>(i,a));
  76. i = +1;
  77. }
  78.  
  79. void wyszukaj(int k)
  80. {
  81. //map<int, Towar*> ::iterator it;
  82. mag.find(k);
  83. // nie wiem jak wypisac ten element
  84. }
  85.  
  86. void wypisz()
  87. {
  88. map<int, Towar*>::iterator it = mag.begin();
  89. for (;it!=mag.end();++it)
  90. {
  91. cout << it->first << " " << it->second << endl;
  92. // nie wiem jak wypisac zawartosc mapy
  93. }
  94. }
  95.  
  96. void wyczysc()
  97. {
  98. mag.clear();
  99. }
  100.  
  101. };
  102.  
  103. int main()
  104. {
  105.  
  106. Komputer *k1=new Komputer("atari", 1);
  107. k1->wyswietlParametry();
  108. Buty *b1 = new Buty("nike", 41);
  109. b1->wyswietlParametry();
  110.  
  111. Magazyn m1;
  112. int iter;
  113. for(iter=0;iter<10;iter++)
  114. {
  115. m1.dodaj(iter, k1);
  116. m1.dodaj(iter, b1);
  117. }
  118. m1.wypisz();
  119. m1.wyszukaj(1);
  120.  
  121. delete k1;
  122. delete b1;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement