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

A triangle is a three-sided polygon. Every triangle has three sides and three an

ID: 3638790 • Letter: A

Question


A triangle is a three-sided polygon. Every triangle has three sides and three
angles, some of which may be the same. Every triangle satis?es the so-called
triangle inequality: the sum of any two sides must be greater than the third
side. Triangles can be classi?ed by the length of their sides or the values of
their angles. The study of triangles is sometimes known as triangle geometry, and is of interest to mathematicians and artists interested in generating
oblique shapes composed of triangles. They usually give beautiful results
and unexpected properties. August Leopold Crelle, a nineteenth century
German mathematician, once remarked, ”It is indeed wonderful that so simple a ?gure as the triangle is so inexhaustible in properties. How many as
yet unknown properties of other ?gures may there not be?”
Your program will take a set of three numbers as input. If these numbers cannot form the sides of a triangle, your program will print a message
indicating so. If these numbers can represent the lengths of the sides of a
triangle, your program will print a report showing the sides of the triangle,
its area and perimeter, and classify the triangle according to the de?nitions:
1. An isosceles triangle is a triangle with (at least) two equal sides.
2. A triangle with all sides equal is called an equilateral triangle.
3. A triangle with no two sides equal is called a scalene triangle.
4. A right triangle is a triangle whose sides, a, b, and c, satisfy the
equation c^2 = a^2 + b^2

Be sure to use this include directive ( #include < cmath > ) in order to use
standard math library functions such as pow and sqrt. Format all output of
real numbers to 4 decimal place. Relevant Formulas:
Let A, B and C denote the sides of the triangle:
P erimeter = A + B + C
Area =
p
S(S - A)(S - B)(S - C), where S =
P erimeter
2
Ensure that numeric values in the report are formatted so that they have
the same number of decimal places as show in the report. For the triple
entered by the user, your program will determine whether the triple could
represent the sides of a triangle. If so, your program should calculate and
display the area and perimeter of the triangle and then classify the triangle,
indicating whether it is a right triangle, an isosceles triangle, an equilateral
triangle and a scalene triangle. On the other hand, if the triple does not satisfy the triangle inequality, your program should print a message indicating
so.
A typical program interaction would be:
Sample Run 1:
Enter the lengths of the sides of a triangle> 7.5 4.5 6
Triangle Program Report
=======================================
The sides of the triangle are:
A = 7.5000; B = 4.5000; C = 6.0000
Perimeter = 18.0000
Area = 13.5000
Classification:
Right: Y
Isosceles: N
Scalene: Y
Equilateral: N
----------------------------------------
Sample Run 2:
Enter the lengths of the sides of a triangle> 1.0 2.0 5.0

Triangle Program Report
=======================================
*** 1.0000, 2.0000, and 5.0000 cannot form the sides of a triangle ***
Sample Run 3:
Enter the lengths of the sides of a triangle> 4.1 4.1 5.3
Triangle Program Report
=======================================
The sides of the triangle are:
A = 4.1000; B = 4.1000; C = 5.3000
Perimeter = 13.5000
Area = 8.2905
Classification:
Right: N
Isosceles: Y
Scalene: N
Equilateral: N
----------------------------------------

Explanation / Answer

#include <iostream>
#include<math.h>
#include<fstream>
using namespace std;
bool istriangle(double,double,double);
void calcTriangle(double, double, double ,double& , double&);
bool isRight(double , double , double );
bool isEquilateral(double , double , double );
bool isIsosceles(double , double , double );
bool isScalene(double , double , double );
int main()
{double a,b,c,area,perimeter;
ifstream input;
  input.open("triple.in");          //open file
  if(input.fail())            //is it ok?
       { cout<<"file did notopen please check it ";
        system("pause");
        return 1;
        }
        cout<<"TriangleProgram Report ======================== ";
input>>a;
while(input)
{input>>b>>c;
   if(istriangle(a,b,c))
      {cout<<"the sides of thetriangle are: A="<<a<<";B= "<<b<<";C="<<c<<endl;
     calcTriangle(a,b,c,perimeter,area);
      cout<<"Perimeter ="<<perimeter<<" Area ="<<area<<" Classification: ";
      cout<<"Right: ";
      if(isRight(a,b,c))
         cout<<"Y ";
      else
         cout<<"N ";
      cout<<"Isosceles:";  
      if(isIsosceles(a,b,c))
         cout<<"Y ";
      else
         cout<<"N ";
      cout<<"Scalene: ";   
      if(isScalene(a,b,c))
         cout<<"Y ";
      else
         cout<<"N ";
      cout<<"Equilateral:";  
      if(isEquilateral(a,b,c))
         cout<<"Y ";
      else
         cout<<"N ";           
      }
   else
      cout<<"***"<<a<<","<<b<<", and "<<c<<" cannot form the sidesof a triangle *** ";
   cout<<"--------------------------- ";
   input>>a;
}
cout<<"*** END OF REPORT*** ======================== ";
system("pause");
return 0;
}
bool isRight(double sideA, double sideB, double sideC)
{double a,b,c;
a=sideA*sideA;
b=sideB*sideB;
c=sideC*sideC;
if(a+b==c||a+c==b||b+c==a)
   return true;
else
      return false;
}

bool isEquilateral(double a, double b, double c)
{if(a==b&&b==c)
      return true;
else
     return false;
}
bool isIsosceles(double a, double b, double c)
{if(a==b||b==c||a==c)
     return true;
else
      return false;
     }
bool isScalene(double a, double b, double c)
{if(a!=b&&a!=c&&b!=c)
      return true;
else
      return false;
}
void calcTriangle(double A, double B, double C,double&perimeter, double& area)
{perimeter=A+B+C;
double S=perimeter/2;
area=sqrt(S*(S-A)*(S-B)*(S-C));
}
bool istriangle(double a,double b,double c)
{
if(a>=b+c||b>=a+c||c>=a+b)
   return false;
else
   return true;
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote