Answer to Question #183014 in C++ for Vincenzo Santoro

Question #183014
  1. Define an enumeration type triangleType that has the values scalene, isosceles, equilateral, and noTriangle.
  2. Write a function triangleShape that takes as parameters three numbers, each of which represents the length of a side of the triangle. The function should return the shape of the triangle. (Note: In a triangle, the sum of the lengths of any two sides is greater than the length of the third side.)
  3. Write a program that prompts the user to input the length of the sides of a triangle and outputs the shape of the triangle.
1
Expert's answer
2021-04-28T04:24:48-0400
#include<iostream>


using namespace std;


/*Define an enumeration type triangleType that has the values scalene, isosceles, equilateral, and noTriangle */
enum TriangleType {scalene, isosceles, equilateral, noTriangle};


/*
Write a function triangleShape that takes as parameters three numbers, each of which represents the length of a side of the triangle. The function should return the shape of the triangle.
*/
TriangleType triangleShape(int l1,int l2,int l3){
	if(l1<=0 || l2<=0 || l3<=0){
		return noTriangle;
	}


	if(l1==l2 && l2==l3){
		return equilateral;   
    }
    else if(l1==l2 || l1==l3 || l2==l3){
       return isosceles;
    }
    else{
       return scalene;
    }
}


int main(){
    /* Write a program that prompts the user to input the length of the sides of a triangle and outputs the shape of the triangle.
    */
    
	int l1;
	int l2;
	int l3;
	
	cout<<"Enter first side: ";
	cin>>l1;
	cout<<"\nEnter second side: ";
	cin>>l2;
	cout<<"\nEnter third side: ";
	cin>>l3;
	
	if(triangleShape(l1,l2,l3)==scalene){
	    cout<<"The triangle is scalene"<<endl;
	}
	if(triangleShape(l1,l2,l3)==isosceles){
		cout<<"The triangle is isosceles"<<endl;
	}
	if(triangleShape(l1,l2,l3)==equilateral){
		cout<<"The triangle is equilateral"<<endl;
	}
	if(triangleShape(l1,l2,l3)==noTriangle){
		cout<<"It is not a triangle"<<endl;
	}
	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