#include <iostream>
using namespace std;
enum TriangleType {scalene, isosceles, equilateral, noTriangle};
class Triangle {
private:
double a, b, c;
TriangleType triangleShape(){
if(a<=0 || b<=0 || c<=0){
return noTriangle;
}
//If all sides are equal
if(a==b && b==c){
return equilateral;
}
//If any two sides are equal
if(a==b || a==c || b==c){
return isosceles;
}
//If none sides are equal
return scalene;
}
public:
//a. Accept the sides of a triangle
void getValues(){
cout<<"Ente a: ";
cin>>a;
cout<<"Ente b: ";
cin>>b;
cout<<"Ente c: ";
cin>>c;
if(a+b<=c){
this->a=0;
this->b=0;
this->c=0;
cout<<"\nERROR - SIDES "<<a<<", "<<b<<", "<<c<<" ARE INVALID FOR A TRIANGLE\n";
}
}
void display(){
//Display result
//b. Display the sides of a triangle
cout <<"a="<<a<<"\nb="<<b<<"\nc="<<c<<"\n";
//d. Find whether the triangle is a Scalene triangle
if(triangleShape()==scalene){
cout <<("Triangle is scalene\n\n");
}
//e. Find whether the triangle is an isosceles triangle
if(triangleShape()==isosceles){
cout <<("Triangle is isosceles\n\n");
}
//c. Find whether the triangle is an equilateral triangle
if(triangleShape()==equilateral){
cout <<("Triangle is equilateral\n\n");
}
if(triangleShape()==noTriangle){
cout <<("It is not a triangle\n\n");
}
}
};
//The start point of the program
int main(){
Triangle Triangle;
Triangle.getValues();
Triangle.display();
system("pause");
return 0;
}
Comments
Leave a comment