Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ a) Define an enumeration type, triangleType, that has the value scalene, isosceles, equilateral, and noTriangle. b) Write a function, triangleShape that takes as parameters

C++

a) Define an enumeration type, triangleType, that has the value scalene, isosceles, equilateral, and noTriangle.

b) Write a function, triangleShape that takes as parameters three numbers, each of which represents the length of a side of thed 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).

c) Write a program that prompts the user to input the length of the side of a triangle and outputs the shape of the triangle.

This is what I have, but it doesn't work

#include

using namespace std;

enum triangleType

{

scalene, isosceles, equilateral, noTriangle

};

triangleType triangleShape(float, float, float);

int main()

{

float s1, s2, s3;

int flag;

cout << "Enter side a: "

cin >> s1;

cout << "Enter side b: "

cin >> s2;

cout << "Enter side c: "

cin >> s3;

flag = triangleShape(s1, s2, s3);

switch(flag)

{

case 0:

cout << "Shape of the triangle is scalene." << endl;

break;

case 1:

cout << "Shape of the triangle is isosceles." << endl;

break;

case 2:

cout << "Shape of the triangle is equilateral." << endl;

break;

case 3:

cout << "Shape of the triangle is noTriangle." << endl;

break;

}

system("pause");

return 0;

}

triangleType triangleShape(float s1, float s2, float s3)

{

triangleType Triangleshape;

if((s1 > (s2 + s3)) || (s2 > (s1 + s3))|| (s3 > (s1 + s2)))

{

Triangleshape = noTriangle;

}

else if((s1 == s2) && (s1 == s3) && (s1 == s3)

{

Triangleshape = equilateral;

}

else if(s1 != s2 && s1 != s3 && s2 != s3)

{

Triangleshape = scalene;

}

else

{

Triangleshape = isosceles;

}

return Triangleshape;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

Analyze the impact of labor unions on health care.

Answered: 1 week ago

Question

2. How were various roles filled?

Answered: 1 week ago