Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<fstream>
- #include<cmath>
- using namespace std;
- class figure
- {
- protected:
- double h;
- public:
- figure()
- {
- h = 0;
- }
- virtual void input(istream& is)
- {
- is >> h;
- }
- virtual void output(ostream& os)
- {
- os << h<<" ";
- }
- virtual double get_extent() = 0;
- };
- class paralelepiped : public figure
- {
- private:
- double a;
- double b;
- public:
- paralelepiped() :figure()
- {
- a = 0;
- b = 0;
- }
- void input(istream& is)
- {
- figure:: input(is);
- is >> a >> b;
- }
- void output(ostream& os)
- {
- figure:: output(cout);
- os << a << " " << b<<endl;
- }
- double get_extent()
- {
- return a*b*h;
- }
- double get_a()
- {
- return a;
- }
- double get_b()
- {
- return b;
- }
- double get_h()
- {
- return h;
- }
- };
- class piramida : public figure
- {
- private:
- double a;
- double b;
- double c;
- public:
- piramida() :figure()
- {
- a = 0;
- b = 0;
- c = 0;
- }
- void input(istream& is)
- {
- figure:: input(is);
- is >> a >> b >> c;
- }
- void output(ostream& os)
- {
- figure:: output(cout);
- os << a << " " << b << " " << c<<endl;
- }
- double get_extent()
- {
- return sqrt(((a + b + c) / 2)* ((a + b + c) / 2 - a)*((a + b + c) / 2 - b)*((a + b + c) / 2 - c))*h;
- }
- double get_h()
- {
- return h;
- }
- };
- class tetraedr : public figure
- {
- private:
- double a;
- public:
- tetraedr() :figure()
- {
- a = 0;
- }
- void input(istream& is)
- {
- is >> a;
- }
- void output(ostream& os)
- {
- figure:: output(cout);
- os << a<<endl;
- }
- double get_extent()
- {
- return a*a*a*sqrt(2) / 12;
- }
- };
- class kylia : public figure
- {
- private:
- double r;
- public:
- kylia() :figure()
- {
- r = 0;
- }
- void input(istream& is)
- {
- is >> r;
- }
- void output(ostream& os)
- {
- figure:: output(cout);
- os << r << endl;
- }
- double get_extent()
- {
- return 4 * 3.141592*r*r*r / 3;
- }
- };
- /*figure* get_max_extent(figure** a, int n)
- {
- int k;
- double max = 0, extent(0);
- for (int i = 0;i < n;i++)
- {
- extent = a[i]->get_extent();
- if (max < extent)
- {
- max = extent;
- k = i;
- }
- }
- return a[k];
- }*/
- figure* get_max_height(figure** a, int n)
- {
- piramida *p;
- double height = 0, max = 0;
- int k;
- for (int i = 0;i < n;i++)
- {
- p = dynamic_cast<piramida*>(a[i]);
- if (p)
- {
- height = p->get_h();
- if (height > max)
- {
- max = height;
- k = i;
- }
- }
- }
- return a[k];
- }
- void sort(figure** arr, int n)
- {
- for (int i = 0; i< n - 1; ++i)
- {
- for (int j = i + 1; j<n; ++j)
- {
- if (arr[i]->get_extent() > arr[j]->get_extent())
- {
- swap(arr[i], arr[j]);
- }
- }
- }
- }
- figure* smallest_side(figure** a, int n)
- {
- paralelepiped* p;
- double min = 1000;
- int k;
- for (int i = 0; i< n; ++i)
- {
- p = dynamic_cast<paralelepiped*>(a[i]);
- if (p)
- {
- if ((min>p->get_b()*p->get_h()) || (min>p->get_a()*p->get_h()))
- {
- if ((min > p->get_b()*p->get_h()) < (min > p->get_a()*p->get_h()))
- {
- min = min > p->get_b()*p->get_h();
- k = i;
- }
- else
- {
- min = min > p->get_a()*p->get_h();
- k = i;
- }
- }
- }
- }
- return a[k];
- }
- void main()
- {
- int n;
- fstream in("figure.txt");
- in >> n;
- char ch;
- figure** a = new figure*[n];
- for (int i = 0; i < n; i++)
- {
- in >> ch;
- if (ch == 'p')
- {
- a[i] = new paralelepiped();
- }
- if (ch == 'm')
- {
- a[i] = new piramida();
- }
- if (ch == 't')
- {
- a[i] = new tetraedr();
- }
- if (ch == 'k')
- {
- a[i] = new kylia();
- }
- a[i]->input(in);
- }
- for (int i = 0; i < n; ++i)
- {
- a[i]->output(cout);
- }
- cout << "================================================================================"<<endl;
- sort(a, n);
- for (int i = 0; i < n; ++i)
- {
- a[i]->output(cout);
- }
- cout << "================================================================================"<<endl;
- figure* o = smallest_side(a, n);
- o->output(cout);
- figure* p = get_max_height(a, n);
- p->output(cout);
- delete[]a;
- in.close();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement