Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <typeinfo>
  6.  
  7. #include "figure.h"
  8. #include "circle.h"
  9. #include "rectangle.h"
  10.  
  11. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  12.  
  13. using namespace std;
  14.  
  15. vector<Figure *>* init(string);
  16. void display(vector<Figure *>*);
  17.  
  18. int main(int argc, char** argv) {
  19. // Figure::counter = 0;
  20. vector<Figure *>* collection = init("danein.txt");
  21.  
  22. display(collection);
  23. }
  24.  
  25. vector<Figure *>* init(string filename) {
  26. vector<Figure *>* collection = new vector<Figure *>;
  27. ifstream file;
  28. string type;
  29. double a;
  30. double b;
  31.  
  32. file.open(filename.c_str());
  33.  
  34. while (true) {
  35. file >> type;
  36. if (type == "q") {
  37. break;
  38. } else if (type == "o") {
  39. file >> a;
  40. collection->push_back(new Circle(a));
  41. } else if (type == "r") {
  42. file >> a >> b;
  43. collection->push_back(new Rectangle(a, b));
  44. }
  45. }
  46.  
  47. file.close();
  48. return collection;
  49. }
  50.  
  51. void display(vector<Figure *>* collection) {
  52. cout << "size = " << collection->size() << endl;
  53. vector<Figure *>::iterator f;
  54. for (f = collection->begin(); f != collection->end(); f++) {
  55. cout << typeid((*f)).name() << "\tarea = " << (*f)->area() << "\tperimeter = " << (*f)->perimeter() << endl;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement