Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. class shape
  8. {
  9. public:
  10. shape() {
  11. }
  12. virtual double perimetr() {
  13. cout << " Периметр фигуры " << endl;
  14. return 0;
  15. }
  16. virtual double square() {
  17. cout << " Площадь фигуры " << endl;
  18. return 0;
  19. }
  20. virtual void show_parametri() {
  21. cout << " Абстрактная фигура " << endl;
  22. }
  23. ~shape() {
  24. cout << "Фигура удалилась" << endl;
  25. }
  26. };
  27.  
  28. class point :public shape {
  29. private:
  30. int x, y;
  31. public:
  32. point() {
  33. x = 0;
  34. y = 0;
  35. }
  36. point(int x, int y) {
  37. this->x = x;
  38. this->y = y;
  39. }
  40. point(point &p) {
  41. x = p.x;
  42. y = p.y;
  43. }
  44. virtual void show_parametri() {
  45. cout << " Это точка" << endl;
  46. cout << " Координаты = " << x << " , " << y << endl;
  47. }
  48. ~point() {
  49. cout << "Точка удалилась" << endl;
  50. }
  51. };
  52.  
  53. class MyStorage {
  54. private:
  55. shape **objects;
  56. int size;
  57. public:
  58. MyStorage(int size)
  59. {
  60. this->size = size;
  61. objects = new shape*[size];
  62. }
  63. void Add(shape *object) {
  64. size++;
  65. objects[size] = object;
  66. }
  67. void SetObject(int index, shape *object) {
  68. objects[index] = object;
  69. }
  70. shape GetObject(int index) {
  71. return *objects[index];
  72. }
  73. shape GetObjectNext(int index) {
  74. if (index + 1 < size || index + 1 == size)
  75. return *objects[index + 1];
  76. }
  77. shape GetObjectLast(int index) {
  78. if (index - 1 > 0 || index - 1 == 0)
  79. return *objects[index - 1];
  80. }
  81.  
  82. bool CheckObject(shape *object) {
  83. for (int i = 0; i < size; i++) {
  84. if (objects[i] == object) {
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. void Delete(int index) {
  91. size--;
  92. for (int i = 0; i < size; i++) {
  93. for (int j = index + 1; j < size; j++) {
  94. objects[index] = objects[j];
  95. }
  96. }
  97. }
  98. int getCount()
  99. {
  100. return size;
  101. }
  102. ~MyStorage() {
  103. cout << "Хранилище удалено" << endl;
  104. }
  105. };
  106.  
  107. int main()
  108. {
  109. setlocale(LC_ALL, "Rus");
  110. MyStorage storage(10);
  111. for (int i = 0; i < storage.getCount(); i++) {
  112. storage.SetObject(i, new point());
  113. }
  114. for (int i = 0; i < storage.getCount(); i++) {
  115. storage.GetObject(i).show_parametri();
  116. }
  117. system("pause");
  118. return 0;
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement