///
// write an application showing hierarchy and multiple inheritance
//  This fun little exercise shows vectors, objects and pointers to objects within a vector.
//  Allocating and deallocating memory added to a container

#include "stdafx.h"
#include <iostream>
#include <list>
#include <vector>

class polygon{
protected:
	int length, width;
public:
	polygon(int x, int y) {
		length = x;
		width = y;
	}
	int area() {
		std::cout << "area" << std::endl;
		return(length * width);
	}
	
};

class rectangle : public polygon {
	
public:
	rectangle(int x, int y):polygon(x, y) {

	}
	bool issquare() {
		if (length == width)
			return true;
		else
			return false;
	}
};

class triangle :public polygon {
public:
	triangle(int x, int y) :polygon(x, y) {}
	int area() {
		std::cout << "triangle" << std::endl;
		return((length * width) / 2);
	}
};

int main()
{
	rectangle rect(1, 2);
	std::cout << rect.area() << std::endl;

	triangle tri(3, 4);
	std::cout << tri.area() << std::endl;
    

	std::list< rectangle > rlist;

	// add 10 
	for (int i = 0; i < 10; i++)
	{
		rectangle rect(5, i);
		rlist.push_back(rect);
	}
	auto iterator = rlist.begin();
	
	while (iterator != rlist.end()) {
		std::cout << (*iterator).area() << std::endl;
		
		iterator++;
	}

	iterator = rlist.begin();
	while (iterator != rlist.end()) {
		iterator = rlist.erase(iterator);
		
	}

	if (rlist.empty())
		std::cout << "empty" << std::endl;

	iterator = rlist.begin();
	while (iterator != rlist.end()) {
		std::cout << (*iterator).area() << std::endl;
		iterator++;
	}

	std::vector< triangle *> vecttri;

	for (int x = 0; x < 10; x++) {
		triangle *triptr = new triangle(5, x);
		vecttri.push_back(triptr);
	}

	auto biterator = vecttri.begin();
	while (biterator != vecttri.end()) {
		std::cout << (*biterator)->area() << std::endl;
		biterator++;
	}

	//ok delete
	biterator = vecttri.begin();

	while (biterator != vecttri.end()) {
		triangle *ptr;
		ptr = *biterator;
		std::cout << ptr->area() << std::endl;
		biterator++;
		delete ptr;
	}
	biterator = vecttri.begin();
	// is there anything there?
	while (biterator != vecttri.end()) {
		//why yes there is!
		std::cout << "element" << std::endl;
		biterator++;
		
	}

	//delete the vector

	vecttri.erase(vecttri.begin(), vecttri.end());
	biterator = vecttri.begin();
	// is there anything there?
	while (biterator != vecttri.end()) {
		//all gone!
		std::cout << "gone" << std::endl;
		biterator++;

	}

		
}