Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / Example_polymorphism / main.cpp
diff options
context:
space:
mode:
Commiteda2b5dee821c474644cd72df4d0bd93b0940ec6 (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-05-17 20:15:26 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-05-17 20:15:26 +0300
Files31906c6c9c1fb1bc923cba908dc0d7f8a6ec6ab2 /Sem. 12/Example_polymorphism/main.cpp
Object-oriented_programming_FMI-eda2b5dee821c474644cd72df4d0bd93b0940ec6.tar
Object-oriented_programming_FMI-eda2b5dee821c474644cd72df4d0bd93b0940ec6.tar.gz
Object-oriented_programming_FMI-eda2b5dee821c474644cd72df4d0bd93b0940ec6.zip
Parentce46289350dae53570d9374506411196b669db1c (diff)
sem 12
1 files changed, 41 insertions, 0 deletions
-rw-r--r--Sem. 12/Example_polymorphism/main.cpp41
diff --git a/Sem. 12/Example_polymorphism/main.cpp b/Sem. 12/Example_polymorphism/main.cpp
new file mode 100644
index 0000000..89a5082
--- /dev/null
+++ b/Sem. 12/Example_polymorphism/main.cpp
@@ -0,0 +1,41 @@
+#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;
+}
+
+void freeCollection(Shape** shapes, size_t shapesCount)
+{
+ for (int i = 0; i < shapesCount; i++)
+ delete shapes[i];
+ delete[] shapes;
+}
+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);
+
+ freeCollection(arr, 4);
+
+
+} \ No newline at end of file