Answer to Question #141575 in C++ for Amani

Question #141575
Define an enumeration tringleType. That has values scalene
1
Expert's answer
2020-11-03T09:15:19-0500
#include <iostream>

using namespace std ;


enum triangleType { scalene , isosceles , equilateral , noTriangle } ;
triangleType triang ( double , double , double ) ;


int main()
{
    double a ;
    double b ;
    double c ;


    int shape ;


    cout << "Side 'a' length:  " << flush ;
    cin >> a ;
    cout << "Side 'b' length:  " << flush ;
    cin >> b ;
    cout << "Side 'c' length:  " << flush ;
    cin >> c ;


    shape = triang ( a , b , c ) ;
    switch (shape)
    {
    case 0:
        cout << "Triangle Shape:  Scalene" << endl ;
        break ;
    case 1:
        cout << "Triangle Shape:  Isosceles" << endl ;
        break ;
    case 2:
        cout << "Triangle Shape:  Equilateral" << endl ;
        break ;
    case 3:
        cout << "Triangle Shape:  -- No Shape --" << endl ;
        break ;
    }

    return 0 ;
}

triangleType triang ( double a , double b , double c )
{

    triangleType shape ;

    if ( ( a > (b + c) ) || ( b > (a + c) ) || ( c > (a + b) ) )
        shape = noTriangle ;        
    else if ( ( a == b ) && ( a == c ) && ( b == c ) )
        shape = equilateral ;
    else if ( a != b && a != c && b != c )
        shape = scalene ;
    else
        shape = isosceles ;

    return shape ;
}

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