Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 12 / Example_polymorphism / main.cpp
blob: 0c93f79b5dd9188bafb3799efc40e9d2557daccd (plain) (blame)
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
#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 checkPointIn(const Shape* const* shapes, size_t shapesCount, int x, int y)
{
	for (int i = 0; i < shapesCount; i++)
		cout << shapes[i]->isPointIn(x,y) << 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);
		std::cout << endl;
		printPers(arr, 4);
		std::cout << endl;

		checkPointIn(arr, 4, 3, 3);
		

		freeCollection(arr, 4);
	
}