Answer to Question #241655 in C++ for Epiiii

Question #241655
Create a Class triangle with three sides a,b and c as its data members Perform

the following operations: a. Accept the sides of a triangle

b. Display the sides of a triangle

c. Find whether the triangle is an equilateral triangle d. Find whether the triangle is a Scalene triangle

e. Find whether the triangle is an isosceles triangle
1
Expert's answer
2021-09-24T03:25:01-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS