Advertisement
evcamels

lr4

Nov 7th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. using namespace std;
  5. class triungle{
  6. public:
  7.     double a,b,c;
  8.     triungle(){}
  9.     triungle(double a, double b, double c){
  10.         this->a = a;
  11.         this->b = b;
  12.         this->c = c;
  13.     }
  14.     void enc(){
  15.         if((a+b) > c && (a+c) > b && (b+c) > a){
  16.             cout << "Треугольник существует!" << endl;
  17.         }else cout << "Треугольник не существует!" << endl;
  18.     }
  19.     void inf(){
  20.         cout << "Сторона А: " << a << endl;
  21.         cout << "Сторона B: " << b << endl;
  22.         cout << "Сторона С: " << c << endl;
  23.     }
  24.     double per(){
  25.         return a+b+c;
  26.     }
  27.     double sq(){
  28.         double p = (a+b+c)/2;
  29.         double s = sqrt(p*(p-a)*(p-b)*(p-c));
  30.         return s;
  31.     }
  32. };
  33. class ravn_triungle :public triungle{
  34. public:
  35.     ravn_triungle(double a, double b, double c): triungle (a,b,c) {}
  36.     ravn_triungle():triungle(){}
  37.     bool pr(){
  38.         if(a == b || a == c || b == c || (a == b && a == c && b == c)){
  39.             return 1;
  40.         }else return 0;
  41.     }
  42.    
  43. };
  44. int main() {
  45.     int N;//число треугольников
  46.     int M;//число равнобедренных треугольников
  47.     cout << "Введите число треугольников: ";
  48.     cin >> N;
  49.     cout << endl;
  50.     cout << "Введите число равнобедренных треугольников: ";
  51.     cin >> M;
  52.     cout << endl;
  53. triungle* arr = new triungle[N];
  54. ravn_triungle* arr1 = new ravn_triungle[M];
  55.     int min = 100000000;
  56. for (int i = 1; i <= N; i++) {
  57.  
  58.     cout << i << ")" << " Треугольник" << endl;
  59.     double a,b,c;
  60.     cout << "Введите сторону А: ";
  61.     cin >> a;
  62.     cout << endl;
  63.     cout << "Введите сторону B: ";
  64.     cin >> b;
  65.     cout << endl;
  66.     cout << "Введите сторону C: ";
  67.     cin >> c;
  68.     cout << endl;
  69.     arr[i] = triungle(a, b, c);
  70.     arr[i].inf();
  71.     cout << arr[i].per() << endl;
  72.     cout << arr[i].sq() << endl;
  73.    
  74. if (arr[i].sq() < min) {
  75.     min = arr[i].sq();
  76. }
  77.     cout << "___________________________" << endl;
  78. }
  79.     cout << "Минимальная площадь треугольника = " << min << endl;
  80.     cout << "___________________________" << endl;
  81. double srS = 0;
  82. for (int i = 1; i <= M; i++) {
  83.  
  84.     cout << i << ")" << " Равнобедренный треугольник" << endl;
  85.  
  86.     double a1,b1,c1;
  87.    
  88.     cout << "Введите сторону А: ";
  89.     cin >> a1;
  90.     cout << endl;
  91.     cout << "Введите сторону B: ";
  92.     cin >> b1;
  93.     cout << endl;
  94.     cout << "Введите сторону C: ";
  95.     cin >> c1;
  96. arr1[i] = ravn_triungle(a1,b1,c1);
  97. if (arr1[i].pr()) {
  98.     srS += arr[i].sq();
  99. }
  100. else {
  101.     srS += 0;
  102. }
  103.     arr1[i].inf();
  104.     cout << arr1[i].per() << endl;
  105.     cout << arr1[i].sq() << endl;
  106. }
  107. double sr = srS / M;
  108.     cout << "Средняя площадь: " << sr << endl;
  109.  
  110. delete[]arr;
  111. delete[]arr1;
  112. return 0;
  113. }
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement