Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Figure
  6. {
  7. string name;
  8.  
  9. public:
  10. Figure(){;}
  11. Figure(string n_name){name = n_name;}
  12.  
  13. virtual double field()
  14. {
  15. return 0;
  16. }
  17.  
  18. virtual string type()
  19. {
  20. return "blank";
  21. }
  22.  
  23. string show_name()
  24. {
  25. return name;
  26. }
  27. };
  28.  
  29. class Square : public Figure
  30. {
  31. double a;
  32.  
  33. public:
  34. Square(string n_name, double n_a):Figure(n_name){a = n_a;}
  35.  
  36. virtual double field()
  37. {
  38. return a*a;
  39. }
  40.  
  41. virtual string type()
  42. {
  43. return "kwadrat";
  44. }
  45. };
  46.  
  47. class Triangle : public Figure
  48. {
  49. double a;
  50. double h;
  51.  
  52. public:
  53. Triangle(string n_name, double n_a, double n_h):Figure(n_name){a = n_a; h = n_h;}
  54.  
  55. virtual double field()
  56. {
  57. return 0.5*a*h;
  58. }
  59.  
  60. virtual string type()
  61. {
  62. return "trojkat";
  63. }
  64. };
  65.  
  66. class Container
  67. {
  68. int size;
  69. int counter;
  70. Figure figures[5];
  71.  
  72. public:
  73. Container(int n_size){size = n_size; counter=0;}
  74.  
  75. void show()
  76. {
  77. for(int i=0;i<counter;i++)
  78. {
  79. cout << figures[i].show_name() << " " << figures[i].type() << " " << figures[i].field() << endl;
  80. }
  81. }
  82.  
  83. void add(Figure n_figure)
  84. {
  85. if(counter<size)
  86. {
  87. figures[counter] = n_figure;
  88. counter++;
  89. }
  90. else cout << "BRAK MIEJSCA!" << endl;
  91. }
  92.  
  93. void del(double field)
  94. {
  95. for(int i=0;i<counter;i++)
  96. {
  97. if(figures[i].field()==field) figures[i] = Figure();
  98. }
  99. }
  100. };
  101.  
  102. int main()
  103. {
  104. int a,h;
  105. string name;
  106.  
  107. int n;
  108. //cin >> n;
  109.  
  110. Container kontener(5);
  111.  
  112. int m;
  113. //cin >> m;
  114.  
  115. string typ;
  116. /*for(int i=0;i<m;i++)
  117. {
  118. cout << "PODAJ TYP: " << endl;
  119. cin >> typ;
  120. if(typ=="kwadrat")
  121. {
  122. cin >> name >> a;
  123.  
  124. }
  125. else if(typ=="trojkat")
  126. {
  127. cin >> name >> a >> h;
  128. }
  129. }*/
  130.  
  131. Square kwadrat("kwadracik",5);
  132. Triangle trojkat("trojkacik",4,3);
  133.  
  134. cout << kwadrat.field() << " " << kwadrat.type() << " " << trojkat.field() << " " << trojkat.type() << endl;
  135.  
  136. kontener.add(kwadrat);
  137. kontener.add(trojkat);
  138. kontener.show();
  139. return 0;
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement