Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 13 / Figures
diff options
context:
space:
mode:
Commit8cf1283a4ffb9fe1901c29c087fa376de82726af (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-02-19 23:30:52 +0200
Filesabdfe6bf526100dcce87a88563100e02adf7605e /Sem. 13/Figures
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.tar.gz
Object-oriented_programming_FMI-8cf1283a4ffb9fe1901c29c087fa376de82726af.zip
Parentd73a7ec225516657dec74472a0491330e9999217 (diff)
clean up
9 files changed, 0 insertions, 231 deletions
-rw-r--r--Sem. 13/Figures/Circle.cpp16
-rw-r--r--Sem. 13/Figures/Circle.h14
-rw-r--r--Sem. 13/Figures/Rectangle.cpp26
-rw-r--r--Sem. 13/Figures/Rectangle.h10
-rw-r--r--Sem. 13/Figures/Shape.cpp52
-rw-r--r--Sem. 13/Figures/Shape.h41
-rw-r--r--Sem. 13/Figures/Triangle.cpp24
-rw-r--r--Sem. 13/Figures/Triangle.h12
-rw-r--r--Sem. 13/Figures/main.cpp36
diff --git a/Sem. 13/Figures/Circle.cpp b/Sem. 13/Figures/Circle.cpp
deleted file mode 100644
index 8226582..0000000
--- a/Sem. 13/Figures/Circle.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "Circle.h"
-
-const double PI = 3.1415;
-Circle::Circle(int x, int y, double radius) : Shape(1), radius(radius)
-{
- setPoint(0, x, y);
-}
-
-double Circle::getArea() const
-{
- return PI * radius * radius;
-}
-double Circle::getPer() const
-{
- return 2 * PI * radius;
-} \ No newline at end of file
diff --git a/Sem. 13/Figures/Circle.h b/Sem. 13/Figures/Circle.h
deleted file mode 100644
index 6449fc1..0000000
--- a/Sem. 13/Figures/Circle.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-#include "Shape.h"
-
-class Circle : public Shape
-{
- double radius;
-
-public:
- Circle(int x, int y, double radius);
-
- double getArea() const override;
- double getPer() const override;
-
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/Rectangle.cpp b/Sem. 13/Figures/Rectangle.cpp
deleted file mode 100644
index 3fa1026..0000000
--- a/Sem. 13/Figures/Rectangle.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "Rectangle.h"
-
-Rectangle::Rectangle(int x1, int y1, int x3, int y3) : Shape(4)
-{
- setPoint(0, x1, y1);
- setPoint(1, x1, y3);
- setPoint(2, x3, y3);
- setPoint(3, x3, y1);
-}
-double Rectangle::getArea() const
-{
- Shape::point p0 = getPointAtIndex(0);
- Shape::point p1 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(3);
-
- return p0.getDist(p1) * p0.getDist(p3);
-
-}
-double Rectangle::getPer() const
-{
- Shape::point p0 = getPointAtIndex(0);
- Shape::point p1 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(3);
-
- return 2*(p0.getDist(p1) + p0.getDist(p3));
-} \ No newline at end of file
diff --git a/Sem. 13/Figures/Rectangle.h b/Sem. 13/Figures/Rectangle.h
deleted file mode 100644
index ccdad8e..0000000
--- a/Sem. 13/Figures/Rectangle.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-#include "Shape.h"
-
-class Rectangle : public Shape
-{
-public:
- Rectangle(int x1, int y1, int x3, int y3);
- double getArea() const override;
- double getPer() const override;
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/Shape.cpp b/Sem. 13/Figures/Shape.cpp
deleted file mode 100644
index 27bb9e9..0000000
--- a/Sem. 13/Figures/Shape.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "Shape.h"
-
-Shape::Shape(size_t pointsCount) : pointsCount(pointsCount)
-{
- points = new point[pointsCount]; // [0,0], [0,0]....
-}
-
-void Shape::copyFrom(const Shape& other)
-{
- points = new point[other.pointsCount];
-
- for (int i = 0; i < other.pointsCount; i++)
- points[i] = other.points[i];
-}
-void Shape::free()
-{
- delete[] points;
-}
-
-Shape::Shape(const Shape& other)
-{
- copyFrom(other);
-}
-Shape& Shape::operator= (const Shape& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Shape::~Shape()
-{
- free();
-}
-
-const Shape::point& Shape::getPointAtIndex(size_t index) const
-{
- if (index >= pointsCount)
- throw std::exception("Invalid point index!");
-
- return points[index];
-}
-
-void Shape::setPoint(size_t pointIndex, int x, int y)
-{
- if (pointIndex >= pointsCount)
- throw std::exception("Invalid point index!");
-
- points[pointIndex] = point(x, y);
-}
diff --git a/Sem. 13/Figures/Shape.h b/Sem. 13/Figures/Shape.h
deleted file mode 100644
index 62f5c41..0000000
--- a/Sem. 13/Figures/Shape.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-#include <iostream>
-
-class Shape // Abstract class - no instances of Shape are allowed!
-{
-protected:
- struct point
- {
- point() :x(0), y(0){}
- point(int x, int y) :x(x), y(y){}
- int x;
- int y;
- double getDist(const point& other) const
- {
- int dx = x - other.x;
- int dy = y - other.y;
-
- return sqrt(dx*dx + dy*dy);
- }
- };
- const point& getPointAtIndex(size_t index) const;
-private:
- point* points;
- size_t pointsCount;
-
- void copyFrom(const Shape& other);
- void free();
-
-
-public:
- Shape(size_t pointsCount);
-
- Shape(const Shape& other);
- Shape& operator=(const Shape& other);
- virtual ~Shape(); //!!!!!!
-
- void setPoint(size_t pointIndex, int x, int y);
-
- virtual double getArea() const = 0; //pure virtual
- virtual double getPer() const = 0; // pure virtual
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/Triangle.cpp b/Sem. 13/Figures/Triangle.cpp
deleted file mode 100644
index 7de831c..0000000
--- a/Sem. 13/Figures/Triangle.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "Triangle.h"
-
-Triangle::Triangle(int x1, int y1, int x2, int y2, int x3, int y3) : Shape(3)
-{
- setPoint(0, x1, y1);
- setPoint(1, x2, y2);
- setPoint(2, x3, y3);
-}
-double Triangle::getArea() const
-{
- Shape::point p1 = getPointAtIndex(0);
- Shape::point p2 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(2);
-
- return abs(p1.x*p2.y + p2.x*p3.y + p3.x*p1.y - p1.y * p2.x - p2.y*p3.x - p3.y*p1.x) / 2.00;
-}
-double Triangle::getPer() const
-{
- Shape::point p1 = getPointAtIndex(0);
- Shape::point p2 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(2);
-
- return p1.getDist(p2) + p2.getDist(p3) + p3.getDist(p1);
-} \ No newline at end of file
diff --git a/Sem. 13/Figures/Triangle.h b/Sem. 13/Figures/Triangle.h
deleted file mode 100644
index c157de8..0000000
--- a/Sem. 13/Figures/Triangle.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-
-#include "Shape.h"
-
-class Triangle : public Shape
-{
-
-public:
- Triangle(int x1, int y1, int x2, int y2, int x3, int y3);
- double getArea() const override;
- double getPer() const override;
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/main.cpp b/Sem. 13/Figures/main.cpp
deleted file mode 100644
index 7e9f9ff..0000000
--- a/Sem. 13/Figures/main.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <iostream>
-using namespace std;
-
-#include "Rectangle.h"
-#include "Circle.h"
-#include "Triangle.h"
-
-
-void printAreas(const Shape* const * shapes, size_t shapesCount)
-{
- for (int i = 0; i < shapesCount; i++)
- cout << shapes[i]->getArea() <<endl;
-}
-void printPers(const Shape* const * shapes, size_t shapesCount)
-{
- for (int i = 0; i < shapesCount; i++)
- cout << shapes[i]->getPer() << endl;
-}
-int main()
-{
- Shape** arr = new Shape*[4];
-
- arr[0] = new Rectangle(3, 4, 6, 8);
- arr[1] = new Circle(3, 3, 4);
- arr[2] = new Circle(1, 4, 5);
- arr[3] = new Triangle(1, 1, 2, 2, 3, 3);
-
- printAreas(arr, 4);
- printPers(arr, 4);
-
- for (int i = 0; i < 4; i++)
- delete arr[i];
- delete[] arr;
-
-
-} \ No newline at end of file