57 lines
1.1 KiB
C++
57 lines
1.1 KiB
C++
#include <iostream>
|
|
#include <list>
|
|
|
|
#include "Shape.hh"
|
|
#include "Square.hh"
|
|
#include "Circle.hh"
|
|
|
|
|
|
using namespace std;
|
|
|
|
void listShapes( list<Shape*> l );
|
|
|
|
int main() {
|
|
|
|
Square square(5);
|
|
|
|
cout << "Square" << endl;
|
|
cout << "Surface : " << square.surface() << endl;
|
|
cout << "Circumference : " << square.circumference() << endl;
|
|
|
|
cout << endl;
|
|
Circle circle(3);
|
|
|
|
cout << "Circle" << endl;
|
|
cout << "Surface : " << circle.surface() << endl;
|
|
cout << "Circumference : " << circle.circumference() << endl;
|
|
|
|
// Shape List
|
|
list<Shape*> l;
|
|
|
|
// Create Circles
|
|
for ( int i = 0 ; i < 4 ; i++ ) {
|
|
l.push_back( new Circle(i*i) );
|
|
}
|
|
|
|
// Create Squares
|
|
for ( int i = 0 ; i < 5 ; i++ ) {
|
|
l.push_back( new Square(i*i) );
|
|
}
|
|
|
|
// List all Shapes
|
|
listShapes( l );
|
|
|
|
// Delete Shapes
|
|
for ( auto it = l.begin() ; it != l.end() ; ++it ) {
|
|
delete (*it);
|
|
}
|
|
}
|
|
|
|
void listShapes( list<Shape*> l ) {
|
|
for ( auto it = l.begin() ; it != l.end() ; ++it ) {
|
|
cout << (*it)->shapeName() << endl;
|
|
cout << "Surface : " << (*it)->surface() << endl;
|
|
cout << "Circumference : " << (*it)->circumference() << endl;
|
|
cout << endl;
|
|
}
|
|
}
|