#include "polygon.h" #include "circle.h" #include enum IOState { NORM, ABNORM }; class ShapeFile { std::istream &str; public: ShapeFile (std::istream &str_): str (str_) {} IOState Read (std::auto_ptr &dx); }; IOState ShapeFile::Read (std::auto_ptr &dx) { int shape_type; str >> shape_type; if (str.eof ()) return ABNORM; double shape_size; str >> shape_size; if (str.eof ()) return ABNORM; if (shape_type == 0) dx = std::auto_ptr (new Circle (shape_size)); else dx = std::auto_ptr (new Polygon (shape_type, shape_size)); return NORM; } std::auto_ptr max_bounding_box_area (ShapeFile &x) { std::auto_ptr max; double max_val = 0; std::auto_ptr dx; IOState sx = x.Read (dx); while (sx == NORM) { double val = dx->bounding_box_area (); if (val >= max_val) { max = dx; max_val = val; } sx = x.Read (dx); } return max; } int main (int argc, char **argv) { ShapeFile x (std::cin); std::auto_ptr s = max_bounding_box_area (x); if (s.get ()) { std::cout << "A legnagyobb befoglaloteglalapu sikidom: " << s->str () << std::endl << "Ennek befoglalo-teglalapja: " << s->bounding_box_area () << std::endl; } else { std::cerr << "HIBA: Ures sikidom-lista!" << std::endl; } }