Advertisement
StoneHaos

nastya5

Dec 7th, 2020
1,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. class Rect {
  8. protected:
  9.     double a;
  10. public:
  11.     Rect() {
  12.         a = 1;
  13.     }
  14.     Rect(double a) {
  15.         this->a = a;
  16.     }
  17.  
  18.     double D() {
  19.         return a * sqrt(2.0);
  20.     }
  21.     double P() {
  22.         return 4 * a;
  23.     }
  24.     double S() {
  25.         return a * a;
  26.     }
  27.     void print() {
  28.         cout << "Rect:\n"
  29.             << "a: " << a << "\n"
  30.             << "D: " << D() << "\n"
  31.             << "P: " << P() << "\n"
  32.             << "S: " << S() << "\n\n";
  33.     }
  34.  
  35.     ~Rect() {}
  36. };
  37.  
  38. class Prizma : public Rect {
  39. protected:
  40.     double h;
  41. public:
  42.     Prizma() {
  43.         a = 1.0;
  44.         h = 1.0;
  45.     }
  46.     Prizma(double a, double h) {
  47.         this->a = a;
  48.         this->h = h;
  49.     }
  50.  
  51.     double V() {
  52.         return a * a * h;
  53.     }
  54.     double S() {
  55.         return a * 4 * h + 2 * a * a;
  56.     }
  57.     double D() {
  58.         return sqrt(pow(a * sqrt(2.0), 2) + pow(h, 2));
  59.     }
  60.  
  61.     void print() {
  62.         cout << "Prizma:\n"
  63.             << "a: " << a << "\n"
  64.             << "h: " << h << "\n"
  65.             << "V: " << V() << "\n"
  66.             << "D: " << D() << "\n"
  67.             << "S: " << S() << "\n\n";
  68.     }
  69.  
  70.  
  71.     ~Prizma() {}
  72. };
  73.  
  74. int main(void) {
  75.     int n, m;
  76.     cin >> n >> m;
  77.     Rect mx;
  78.     bool flag = false;
  79.     for (int i = 0; i < n; ++ i) {
  80.         double a;
  81.         cout << "Rect" << i << endl;
  82.         cin >> a;
  83.         if (!flag) {
  84.             flag = true;
  85.             mx = Rect(a);
  86.         }
  87.         else {
  88.             if (mx.S() < Rect(a).S())
  89.                 mx = Rect(a);
  90.         }
  91.     }
  92.     flag = false;
  93.     Prizma mpx;
  94.     for (int i = 0; i < m; ++ i) {
  95.         double a, h;
  96.         cout << "Prizma" << i << endl;
  97.         cin >> a >> h;
  98.         if (!flag) {
  99.             flag = true;
  100.             mpx = Prizma(a, h);
  101.         }
  102.         else {
  103.             if (mpx.D() < Prizma(a, h).D())
  104.                 mpx = Prizma(a, h);
  105.         }
  106.     }
  107.     mx.print();
  108.     mpx.print();
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement