Guest User

Untitled

a guest
Jul 16th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. // laborki 5.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <conio.h>
  6. #include <vector>
  7.  
  8. class DoRegulacjiWysokosci
  9. {
  10. public:
  11. float wysokosc;
  12. virtual void ZmienWysokoscO(const float o);
  13. virtual const float Wysokosc() const;
  14. };
  15.  
  16. class DoWyswietlaniaStanu
  17. {
  18. public:
  19. virtual void WyswietlStan() const;
  20. };
  21.  
  22.  
  23. class SrodekTransportu : public DoRegulacjiWysokosci, public DoWyswietlaniaStanu
  24. {
  25. };
  26.  
  27. void ZmienWysokoscO(std::vector<SrodekTransportu*> &T,const float o)
  28. {
  29. std::vector<SrodekTransportu*>::const_iterator it=T.begin();
  30. std::vector<SrodekTransportu*>::const_iterator endit=T.end();
  31. for(; it !=endit; ++it)
  32. {
  33. (*it)->ZmienWysokoscO(o);
  34. (*it)->WyswietlStan();
  35. }
  36. }
  37.  
  38. ////////////////////
  39. class Samochod : public SrodekTransportu
  40. {
  41. void ZmienWysokoscO(const float o);
  42. const float Wysokosc() const;
  43. void WyswietlStan() const;
  44. };
  45.  
  46. void Samochod::ZmienWysokoscO(float o)
  47. {
  48. Samochod::wysokosc=0;
  49. }
  50.  
  51. const float Samochod::Wysokosc() const
  52. {
  53. return Samochod::wysokosc;
  54. }
  55.  
  56. void Samochod::WyswietlStan() const
  57. {
  58. printf("Samochod - Wysokosc :%f", Wysokosc());
  59. }
  60. //////////////////////////
  61. class Samolot : public SrodekTransportu
  62. {
  63. void ZmienWysokoscO(const float o);
  64. const float Wysokosc() const;
  65. void WyswietlStan() const;
  66. };
  67.  
  68.  
  69. void Samolot::ZmienWysokoscO(const float o)
  70. {
  71. if(o>0) Samolot::wysokosc=o;
  72. if(o<=0) Samolot::wysokosc=0;
  73. }
  74.  
  75. const float Samolot::Wysokosc() const
  76. {
  77. return Samolot::wysokosc;
  78. }
  79.  
  80. void Samolot::WyswietlStan() const
  81. {
  82. printf("Samolot - Wysokosc :%f", Wysokosc());
  83. }
  84.  
  85. ////////////////////////////////
  86. class OkretPodwodny : public SrodekTransportu
  87. {
  88. void ZmienWysokoscO(const float o);
  89. const float Wysokosc() const;
  90. void WyswietlStan() const;
  91. };
  92.  
  93. void OkretPodwodny::ZmienWysokoscO(const float o)
  94. {
  95. if(o<0) OkretPodwodny::wysokosc=o;
  96. if(o>=0) OkretPodwodny::wysokosc=0;
  97. }
  98.  
  99. const float OkretPodwodny::Wysokosc() const
  100. {
  101. return OkretPodwodny::wysokosc;
  102. }
  103.  
  104. void OkretPodwodny::WyswietlStan() const
  105. {
  106. printf("Okret Podwodny - Glebokosc :%f", Wysokosc());
  107. }
  108.  
  109. int _tmain(int argc, _TCHAR* argv[])
  110. {
  111. OkretPodwodny *A1;
  112. OkretPodwodny *A2;
  113. OkretPodwodny *A3;
  114. Samolot *A4;
  115. Samolot *A5;
  116. Samolot *A6;
  117. Samochod *A7;
  118. Samochod *A8;
  119. Samochod *A9;
  120. std::vector<SrodekTransportu*> T;
  121. T.push_back(A1);
  122. T.push_back(A2);
  123. T.push_back(A3);
  124. T.push_back(A4);
  125. T.push_back(A5);
  126. T.push_back(A6);
  127. T.push_back(A7);
  128. T.push_back(A8);
  129. T.push_back(A9);
  130.  
  131. ZmienWysokoscO(T,1);
  132. _getch();
  133. return 0;
  134. }
Add Comment
Please, Sign In to add comment