Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- class triungle{
- public:
- double a,b,c;
- triungle(){}
- triungle(double a, double b, double c){
- this->a = a;
- this->b = b;
- this->c = c;
- }
- void enc(){
- if((a+b) > c && (a+c) > b && (b+c) > a){
- cout << "Треугольник существует!" << endl;
- }else cout << "Треугольник не существует!" << endl;
- }
- void inf(){
- cout << "Сторона А: " << a << endl;
- cout << "Сторона B: " << b << endl;
- cout << "Сторона С: " << c << endl;
- }
- double per(){
- return a+b+c;
- }
- double sq(){
- double p = (a+b+c)/2;
- double s = sqrt(p*(p-a)*(p-b)*(p-c));
- return s;
- }
- };
- class ravn_triungle :public triungle{
- public:
- ravn_triungle(double a, double b, double c): triungle (a,b,c) {}
- ravn_triungle():triungle(){}
- bool pr(){
- if(a == b || a == c || b == c || (a == b && a == c && b == c)){
- return 1;
- }else return 0;
- }
- };
- int main() {
- int N;//число треугольников
- int M;//число равнобедренных треугольников
- cout << "Введите число треугольников: ";
- cin >> N;
- cout << endl;
- cout << "Введите число равнобедренных треугольников: ";
- cin >> M;
- cout << endl;
- triungle* arr = new triungle[N];
- ravn_triungle* arr1 = new ravn_triungle[M];
- int min = 100000000;
- for (int i = 1; i <= N; i++) {
- cout << i << ")" << " Треугольник" << endl;
- double a,b,c;
- cout << "Введите сторону А: ";
- cin >> a;
- cout << endl;
- cout << "Введите сторону B: ";
- cin >> b;
- cout << endl;
- cout << "Введите сторону C: ";
- cin >> c;
- cout << endl;
- arr[i] = triungle(a, b, c);
- arr[i].inf();
- cout << arr[i].per() << endl;
- cout << arr[i].sq() << endl;
- if (arr[i].sq() < min) {
- min = arr[i].sq();
- }
- cout << "___________________________" << endl;
- }
- cout << "Минимальная площадь треугольника = " << min << endl;
- cout << "___________________________" << endl;
- double srS = 0;
- for (int i = 1; i <= M; i++) {
- cout << i << ")" << " Равнобедренный треугольник" << endl;
- double a1,b1,c1;
- cout << "Введите сторону А: ";
- cin >> a1;
- cout << endl;
- cout << "Введите сторону B: ";
- cin >> b1;
- cout << endl;
- cout << "Введите сторону C: ";
- cin >> c1;
- arr1[i] = ravn_triungle(a1,b1,c1);
- if (arr1[i].pr()) {
- srS += arr[i].sq();
- }
- else {
- srS += 0;
- }
- arr1[i].inf();
- cout << arr1[i].per() << endl;
- cout << arr1[i].sq() << endl;
- }
- double sr = srS / M;
- cout << "Средняя площадь: " << sr << endl;
- delete[]arr;
- delete[]arr1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement