Website Summary Files Commits Branches @commit @diff @stats
path: root / Polymorphism / Figures
diff options
context:
space:
mode:
1 files changed, 20 insertions, 0 deletions
-rw-r--r--Polymorphism/Figures/Rectangle.hpp20
diff --git a/Polymorphism/Figures/Rectangle.hpp b/Polymorphism/Figures/Rectangle.hpp
new file mode 100644
index 0000000..99b4b50
--- /dev/null
+++ b/Polymorphism/Figures/Rectangle.hpp
@@ -0,0 +1,20 @@
+#include "Figure.hpp"
+class Rectangle : public Figure
+{
+public:
+ Rectangle(int x1, int y1, int x2, int y2) : Figure(4)
+ {
+ setPoint(0, x1, y1);
+ setPoint(1, x2, y1);
+ setPoint(2, x2, y2);
+ setPoint(3, x1, y2);
+ }
+ double getPer()
+ {
+ return 2 * (getPoint(0).getDistTo(getPoint(1)) + getPoint(0).getDistTo(getPoint(3)));
+ }
+ double getArea()
+ {
+ return getPoint(0).getDistTo(getPoint(1))* getPoint(1).getDistTo(getPoint(2));
+ }
+};