Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<math.h>
- using namespace std;
- class Triunghi{
- private:
- float a,b,c;
- public:
- Triunghi(float a, float b, float c);
- static int esteValid(float a, float b, float c);
- float perimetru();
- float aria();
- int esteDreptunghic();
- };
- Triunghi:: Triunghi(float a, float b, float c){
- this->a=a;
- this->b=b;
- this->c=c;
- cout<<"C initializare cu param"<<endl;
- }
- int Triunghi:: esteValid(float a, float b, float c){
- int valid=0;
- if(a+b>c && a+c>b && b+c>a)
- valid=1;
- return valid;
- }
- float Triunghi:: perimetru(){
- float p=a+b+c;
- return p;
- }
- float Triunghi::aria(){
- float p=perimetru()/2;
- float ar=sqrt(p*(p-a)*(p-b)*(p-c));
- return ar;
- }
- int Triunghi:: esteDreptunghic(){
- int dreptunghic=0;
- float x=a*a;
- float y=b*b;
- float z=c*c;
- if(x==y+z || y==x+z || z==x+y)
- dreptunghic=1;
- return dreptunghic;
- }
- int main(){
- float a=3,b=4,c=5;
- if(Triunghi::esteValid(a,b,c)){
- Triunghi t(a,b,c);
- cout<<"Perimetrul este: "<<t.perimetru()<<endl;
- cout<<"Aria este: "<<t.aria()<<endl;
- cout<<"Este dreptunghic - "<<(t.esteDreptunghic()?" Da ":" Nu ")<<endl;
- }else{
- cout<<"Nu pot forma un triunghi"<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement