#include <iostream>
#include <ctime>
#include <vector>
using namespace std;
const int rectArraySize = 4;
const int circArraySize = 3;
const int countOfFigure = 17;
const int R = 10;
class Field {
public:
};
class Figure {
public:
double* geometry;
double* speedPointer;
void Field(vector <Circle> &circles, vector <Rectangle> &rects) {
};
virtual void move() {
};
virtual void rotate() {
};
//virtual ~figure() {
//cout << "DELETION";
//};
virtual double getCoordX() {
return this->geometry[0];
};
virtual double getCoordY() {
return this->geometry[1];
};
};
class Circle : public Figure {
public:
Circle(double centerCoordX, double centerCoordY, double radius) {
geometry = new double[rectArraySize];
geometry[0] = centerCoordX;
geometry[1] = centerCoordY;
geometry[2] = radius;
}
double getRadius() {
return this->geometry[2];
};
};
class Rectangle : public Figure {
public:
Rectangle(double centerCoordX, double centerCoordY, double height, double width) {
geometry = new double[rectArraySize];
geometry[0] = centerCoordX;
geometry[1] = centerCoordY;
geometry[2] = height;
geometry[3] = width;
}
double getWidth() {
return this->geometry[2];
};
double getHeight() {
return this->geometry[3];
}
};
ostream& operator<<(ostream& os, Circle& c) {
return os << "(X: " << c.getCoordX() << ", Y:" << c.getCoordY() << "). Radius: " << c.getRadius() << endl;
}
ostream& operator<<(ostream& os, Rectangle& r) {
return os << "(X: " << r.getCoordX() << ", Y:" << r.getCoordY() << "). Width: " << r.getWidth() << ", Heigth: " << r.getHeight() << endl;
}
int main() {
int lastCircleIndex = 0;
int lastRectIndex = 0;
int squareSide = 100 * R;
srand(time(0));
vector <Circle> circleArray;
vector <Rectangle> rectangleArray;
vector <Circle>* circlePointer = &circleArray;
vector <Rectangle>* rectanglePointer = &rectangleArray;
for (int i = 0; i < countOfFigure; i++) {
int currentFigure = rand() % 2 + 1;
switch (currentFigure) {
case 1:
{
lastCircleIndex++;
int centerCoordX = R + rand() % (100 - 2 * R);
int centerCoordY = R + rand() % (100 - 2 * R);
Circle Cir(centerCoordX, centerCoordY, R);
circleArray.push_back(Cir);
}
break;
case 2:
{
lastRectIndex++;
int height = R;
int width = R;
int centerCoordX = R / 2 + rand() % (100 - R);
int centerCoordY = R / 2 + rand() % (100 - R);
Rectangle rect(centerCoordX, centerCoordY, height, width);
rectangleArray.push_back(rect);
}
break;
}
}
Field field(circlePointer, rectanglePointer);
cout << "-----------Circles" << lastCircleIndex << "----------\n";
for (int i = 0; i < lastCircleIndex; i++) {
//cout << circleArray[i].geometry[0] << " " << circleArray[i].geometry[1] << " " << circleArray[i].geometry[2] << " " << endl;
cout << circleArray[i];//после перегрузки
}
cout << "-----------Rects" << lastRectIndex << "-----------\n";
for (int i = 0; i < lastRectIndex; i++) {
//cout << rectangleArray[i].geometry[0] << " " << rectangleArray[i].geometry[1] << " " << rectangleArray[i].geometry[2] << " " << rectangleArray[i].geometry[2] << " " << endl;
cout << rectangleArray[i];// после перегрузки
}
return 0;
}
void Field(vector <Circle> &circles, vector <Rectangle> &rects) {