Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- #include <typeinfo>
- #include "figure.h"
- #include "circle.h"
- #include "rectangle.h"
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- using namespace std;
- vector<Figure *>* init(string);
- void display(vector<Figure *>*);
- int main(int argc, char** argv) {
- // Figure::counter = 0;
- vector<Figure *>* collection = init("danein.txt");
- display(collection);
- }
- vector<Figure *>* init(string filename) {
- vector<Figure *>* collection = new vector<Figure *>;
- ifstream file;
- string type;
- double a;
- double b;
- file.open(filename.c_str());
- while (true) {
- file >> type;
- if (type == "q") {
- break;
- } else if (type == "o") {
- file >> a;
- collection->push_back(new Circle(a));
- } else if (type == "r") {
- file >> a >> b;
- collection->push_back(new Rectangle(a, b));
- }
- }
- file.close();
- return collection;
- }
- void display(vector<Figure *>* collection) {
- cout << "size = " << collection->size() << endl;
- vector<Figure *>::iterator f;
- for (f = collection->begin(); f != collection->end(); f++) {
- cout << typeid((*f)).name() << "\tarea = " << (*f)->area() << "\tperimeter = " << (*f)->perimeter() << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement