Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project 6 consists of one C++ Program: Concepts tested by this program: 1. To wo

ID: 3767478 • Letter: P

Question

Project 6 consists of one C++ Program: Concepts tested by this program: 1. To work with functions 2. To work with Boolean expressions 3. To learn to sort 3 scalar values 4. To learn the advantages of sorting values first 5. To learn the advantage of using functions 6. To learn to test all possible paths in a program 7. To learn to write a longer program step by step. Program: Write, compile, and run a C++ program that will allow the user to enter sets of 3 lengths and then tell what kind of triangle the 3 lengths form. Function main should consist mainly of a loop and calls to functions. All of the work is done inside functions. The main loop should end when the user enters 0 for each side. Terms used to describe triangles: Equilateral: the lengths of all 3 sides are equal Isosceles: any two sides (but not all 3) are equal Scalene: no sides are equal Right: C*C = A*A + B*B Obtuse: C*C > A*A + B*B Acute: C*C < A*A + B*B It is possible that the user enters 3 lengths that cannot make a triangle, 3, 4, and 10 for example. If the 3 lengths cannot make a triangle, display an appropriate message. (If not a triangle, you should not then display obtuse or isosceles for instance.) Method: If you sort the 3 sides such that a<=b<=c it is easier to do the next steps. For instance, if we know the sides are in order and a==c then all 3 sides must be equal. In addition to main, your program should have the following functions: • A function to swap two double values. • A function to sort the 3 sides such that a<=b<=c • A function to input the 3 sides. • A function to return or display equilateral, isosceles, or scalene. • A function to return or display right, acute, or obtuse. • A function that returns true if the 3 values can form a triangle, false if not.

Explanation / Answer

#include<iostream.h>

#include<conio.h>

int a,b,c;

void main()

{

double tr;

a= inputSide();

b=inputSide();

c=inputSide();

cout<<"The sides you have enters can be sorted in ascending order as:";

sortSides(a,b,c);

tr= isTriangle(a,b,c);

cout<<"The entered sides form the triangle of type:";

getType(a,b,c);

return 0;

}

int inputSide()

{

int d;

cout<< "enter the side of triangle";

cin>>d;

return d;

}

void sortSides(int &a, int &b, int &c)

{

if(a>b)

{

temp= a;

a=b;

b=temp;

}

if(b>c)

{

temp=b;

b=c;

c=temp;

}

if(a>b)

{

temp=a;

a=b;

b=temp;

}

cout<<a<<" "<<b<<" "<<c<<endl;

}

bool isTriangle(int a , int b, int c)

{

if(a<0 && b<0 &&c<0)

return false;

else if (a+b>c || b+c>a || a+c>b)

return true;

else

return true;

}

void getType(int a, int b, int c)

{

if(a==b && b==c)

cout<<"Triangle is Equilateral"<<endl;

else if(a==b ||b==c || a==c)

cout<<"Triangle is isosceles"<<endl;

else if( a!= b && b!=c && a !=c)

cout<< "Triangle is scalane"<<endl;

else if( c*c= a*a + b*b)

cout<<"Tiangle is Right triangle"<<endl;

else if( c*c >a*a + b*b)

cout<<"Triangle is Obtuse" <<endl;

else if (c*c <a*a +b*b)

cout<< "Triangle is acute "<,endl;

else

cout<<"Triangle is not from given types";

}