Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- using namespace std;
- class shape
- {
- public:
- shape() {
- }
- virtual double perimetr() {
- cout << " Периметр фигуры " << endl;
- return 0;
- }
- virtual double square() {
- cout << " Площадь фигуры " << endl;
- return 0;
- }
- virtual void show_parametri() {
- cout << " Абстрактная фигура " << endl;
- }
- ~shape() {
- cout << "Фигура удалилась" << endl;
- }
- };
- class point :public shape {
- private:
- int x, y;
- public:
- point() {
- x = 0;
- y = 0;
- }
- point(int x, int y) {
- this->x = x;
- this->y = y;
- }
- point(point &p) {
- x = p.x;
- y = p.y;
- }
- virtual void show_parametri() {
- cout << " Это точка" << endl;
- cout << " Координаты = " << x << " , " << y << endl;
- }
- ~point() {
- cout << "Точка удалилась" << endl;
- }
- };
- class MyStorage {
- private:
- shape **objects;
- int size;
- public:
- MyStorage(int size)
- {
- this->size = size;
- objects = new shape*[size];
- }
- void Add(shape *object) {
- size++;
- objects[size] = object;
- }
- void SetObject(int index, shape *object) {
- objects[index] = object;
- }
- shape GetObject(int index) {
- return *objects[index];
- }
- shape GetObjectNext(int index) {
- if (index + 1 < size || index + 1 == size)
- return *objects[index + 1];
- }
- shape GetObjectLast(int index) {
- if (index - 1 > 0 || index - 1 == 0)
- return *objects[index - 1];
- }
- bool CheckObject(shape *object) {
- for (int i = 0; i < size; i++) {
- if (objects[i] == object) {
- return true;
- }
- }
- return false;
- }
- void Delete(int index) {
- size--;
- for (int i = 0; i < size; i++) {
- for (int j = index + 1; j < size; j++) {
- objects[index] = objects[j];
- }
- }
- }
- int getCount()
- {
- return size;
- }
- ~MyStorage() {
- cout << "Хранилище удалено" << endl;
- }
- };
- int main()
- {
- setlocale(LC_ALL, "Rus");
- MyStorage storage(10);
- for (int i = 0; i < storage.getCount(); i++) {
- storage.SetObject(i, new point());
- }
- for (int i = 0; i < storage.getCount(); i++) {
- storage.GetObject(i).show_parametri();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement