Advertisement
Roctik

Untitled

Jun 24th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include<string.h>
  4. #include<math.h>
  5.  
  6. using namespace std;
  7. class Triangle{
  8.   public:
  9.   int a,b,c;
  10.   string color;
  11.  
  12.   Triangle(){
  13.      cout << "Конструктор" << endl;
  14.   }
  15.   Triangle(int _a, int _b, int _c, string _color){
  16.       a=_a;
  17.       b=_b;
  18.       c=_c;
  19.       color=_color;
  20.   }
  21.  
  22.   void setSide(){
  23.       cout<<"Введіть сторону а: ";
  24.       cin>>a;
  25.      
  26.       cout<<"Введіть сторону б: ";
  27.       cin>>b;
  28.      
  29.       cout<<"Введіть сторону с: ";
  30.       cin>>c;
  31.      
  32.       cout<<"Введіть колір: ";
  33.       cin>>color;
  34.   }
  35.  
  36.   double getPer(){
  37.       return a+b+c;
  38.   }
  39.    
  40.     double getSquare(){
  41.         double p=getPer()/2;
  42.         return sqrt(p*(p-a)*(p-b)*(p-c));
  43.     }
  44.    
  45.     void print(){
  46.         cout<<"Сторона а: "<<a<<endl;
  47.         cout<<"Сторона б "<<b<<endl;
  48.         cout<<"Сторона с: "<<c<<endl;
  49.         cout<<"Колір: "<<color<<endl;
  50.         cout<<"Периметр: "<<getPer()<<endl;
  51.         cout<<"Плоша: "<<getSquare()<<endl;
  52.        
  53.     }
  54. };
  55.  
  56. int main()
  57. {
  58.     Triangle obj;
  59.     obj.setSide();
  60.     obj.print();
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement