1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include "vertex.h"
#include "Shape.h"
using namespace std;
class Polygon : public Shape {
public:
Polygon(int Xpol = 0, int Ypol = 0, Vertex* varr = 0, int num = 0){
if (num > 0) {
polSize = new Vertex[1];
polSize[0] = Vertex(num);
fp = new Vertex[1];
fp[0] = Vertex(Xpol, Ypol);
Vx = new Vertex[num];
for (int ix=0; ix<num; ix++){
Vx[ix] = varr[ix];
}
}
else Vx = 0;
}
virtual ~Polygon() {
delete[] polSize;
delete[] Vx;
delete[] fp;
}
virtual Shape* clone() const {
return new Polygon(fp[0].postX(), fp[0].postY(), Vx, polSize[0].postZ());
}
virtual void print() const {
cout << "POLYGON: (" << fp[0].postX() << ", " << fp[0].postY() << ") { ";
for (int ix=0; ix<polSize[0].postZ(); ix++){
cout << "(" << Vx[ix].postX() << ", " << Vx[ix].postY() << ") ";
}
cout << "}" << endl;
}
virtual double area() const {
double s = 0.0;
for (int ix=1; ix<polSize[0].postZ(); ix++){
s += (Vx[ix -1].postX() * Vx[ix].postY()) - (Vx[ix].postX() * Vx[ix -1].postY());
}
return abs(s / 2);
}
virtual void Tabort(Vertex& Vrtx) const {
for (int ix=0; ix<polSize[0].postZ(); ix++) {
if (Vrtx.postX() == polSize[ix].postX() && Vrtx.postY() == polSize[ix].postY()) {
delete polSize;
}
}
}
};
class Rectangle : public Shape {
public:
Rectangle(int p1 = 0, int p2 = 0, int p3 = 0, int p4 = 0){
Vx = new Vertex[2];
Vx[0] = Vertex(p1, p2);
Vx[1] = Vertex(p3, p4);
}
virtual ~Rectangle() {
delete[] Vx;
}
virtual Shape* clone() const {
return new Rectangle(Vx[0].postX(), Vx[0].postY(), Vx[1].postX(), Vx[1].postY());
}
virtual void print() const {
cout << "RECTANGLE: (" << Vx[0].postX() << ", " << Vx[0].postY() << ") (" << Vx[1].postX() << ", " << Vx[1].postY() << ")" << endl;
}
virtual double area() const {
double a = 0.0;
a = Vx[1].postY() * Vx[1].postX();
return a;
}
virtual void Tabort(Vertex& Vrtx) const {
for (int ix=0; 2; ix++){
if (Vrtx.postX() == Vx[ix].postX() && Vrtx.postY() == Vx[ix].postY()) {
delete Vx;
}
}
}
};
class Circle : public Shape{
public:
Circle(int c1 = 0, int c2 = 0, int c3 = 0){
Vx = new Vertex[2];
Vx[0] = Vertex(c1, c2);
Vx[1] = Vertex(c3);
}
virtual Shape* clone() const {
return new Circle(Vx[0].postX(), Vx[0].postY(), Vx[1].postZ());
}
virtual void print() const {
cout << "CIRCLE: (" << Vx[0].postX() << ", " << Vx[0].postY() << ") " << Vx[1].postZ() << endl;
}
virtual double area() const {
double a;
a = Vx[1].postZ() * Vx[1].postZ() * M_PI;
return a;
}
virtual void Tabort(Vertex& Vrtx) const {
if (Vrtx.postX() == Vx[0].postX() && Vrtx.postY() == Vx[0].postY()) {
delete Vx;
}
}
};
class Point : public Shape{
public:
Point(int c1 = 0, int c2 = 0, int c3 = 0){
Vx = new Vertex[2];
Vx[0] = Vertex(c1, c2);
Vx[1] = Vertex(c3);
}
virtual Shape* clone() const {
return new Point(Vx[0].postX(), Vx[0].postY(), Vx[1].postZ());
}
virtual void print() const {
cout << "POINT: (" << Vx[0].postX() << ", " << Vx[0].postY() << ") " << Vx[1].postZ() << endl;
}
virtual double area() const {
return Vx[1].postZ();
}
virtual void Tabort(Vertex& Vrtx) const {
if (Vrtx.postX() == Vx[0].postX() && Vrtx.postY() == Vx[0].postY()) {
delete Vx;
}
}
};
|