A triangle is a three-sided polygon. Every triangle has three sides and three an
ID: 3531163 • 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,
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 not open please check it ";
system("pause");
return 1;
}
cout<<"Triangle Program Report ======================== ";
input>>a;
while(input)
{input>>b>>c;
if(istriangle(a,b,c))
{cout<<"the sides of the triangle 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 sides of 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;
}
Here is what I solved before. Please modify the figures as per your question. Let me know if you want some clarification on it. Please rate 5 stars if I succeeded in helping you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.