Advertisement
madalinaradu

triunghi

Apr 15th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include<math.h>
  3. using namespace std;
  4.  
  5. class Triunghi{
  6.     private:
  7.         float a,b,c;
  8.     public:
  9.         Triunghi(float a, float b, float c);
  10.         static int esteValid(float a, float b, float c);
  11.         float perimetru();
  12.         float aria();
  13.         int esteDreptunghic();
  14.  
  15. };
  16. Triunghi:: Triunghi(float a, float b, float c){
  17.     this->a=a;
  18.     this->b=b;
  19.     this->c=c;
  20.     cout<<"C initializare cu param"<<endl;
  21.  
  22.  }
  23. int Triunghi:: esteValid(float a, float b, float c){
  24.     int valid=0;
  25.     if(a+b>c && a+c>b && b+c>a)
  26.         valid=1;
  27.     return valid;
  28. }
  29. float Triunghi:: perimetru(){
  30.     float p=a+b+c;
  31.     return p;
  32.  
  33. }
  34. float Triunghi::aria(){
  35.     float p=perimetru()/2;
  36.     float ar=sqrt(p*(p-a)*(p-b)*(p-c));
  37.     return ar;
  38. }
  39. int Triunghi:: esteDreptunghic(){
  40.     int dreptunghic=0;
  41.     float x=a*a;
  42.     float y=b*b;
  43.     float z=c*c;
  44.  
  45.     if(x==y+z || y==x+z || z==x+y)
  46.         dreptunghic=1;
  47.     return dreptunghic;
  48. }
  49.  
  50. int main(){
  51.     float a=3,b=4,c=5;
  52.     if(Triunghi::esteValid(a,b,c)){
  53.        Triunghi t(a,b,c);
  54.        cout<<"Perimetrul este: "<<t.perimetru()<<endl;
  55.        cout<<"Aria este: "<<t.aria()<<endl;
  56.        cout<<"Este dreptunghic  - "<<(t.esteDreptunghic()?" Da ":" Nu ")<<endl;
  57.     }else{
  58.         cout<<"Nu pot forma un triunghi"<<endl;
  59.     }
  60.  
  61.  
  62.   return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement