1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
using std::fixed;
#include <string>
using std::string;
#include <cmath>
float PI = 3.1415926;
void getSSS();
void printInfo(float a, float b, float c, float D, float S);
int main()
{
string triangleType;
cout << "Enter type of triangle definition: SSS, SAS, AAS, ASA: ";
cin >> triangleType;
cout << endl;
if (triangleType == "SSS")
{
getSSS();
}
/// else if (triangleType == "SAS") ...
else
{
cout << "Type " << triangleType << " not supported." << endl;
}
return 0;
}
void getSSS()
{
float a, b, c, D, S;
cout << "Enter the lengths of the three sides of the triangle:";
cin >> a >> b >> c;
cout << endl;
S = (a+b+c)/2.0; // S is the semiperimeter of the triangle
D = S*(S-a)*(S-b)*(S-c);//D is the square of the area of the triangle
if(D<=0)
{
cout << "That triangle is not possible! Check your worksheet and try again!" << endl;
}
else
{
printInfo(a, b, c, D, S);
}
}
void printInfo(float a, float b, float c, float D, float S)
{
float A, B, C, Area, R;
cout.precision(2);
cout << fixed;
if((a==b || b==c || c==a) && !(a==b && b==c && c==a))
cout << "The triangle is ISOSCELES" << endl;
if(a==b && b==c && c==a)
cout << "The triangle is EQUILATERAL" << endl;
if(a!=b && b!=c && c!=a)
cout << "The triangle is SCALENE" << endl;
Area = sqrt(D);
R = (a*b*c)/(4.0*Area);
cout << "PERIMETER = " << (2.0*S) << "cm" << endl;
cout << "AREA = " << Area << "cm^2" << endl;
cout << "CIRCUM RADIUS = " << R << "cm" << endl;
cout << endl;
// using sine rule,we get...
A = (180.0/PI)*asin(a/(2.0*R));
B = (180.0/PI)*asin(b/(2.0*R));
C = (180.0/PI)*asin(c/(2.0*R));
if(A==90.0 || B==90.0 || C==90.0)
cout << "The triangle is RIGHT ANGLED" << endl;
if(A<90.0 && B<90.0 && C<90.0)
cout << "The triangle is ACUTE ANGLED" << endl;
if(A>90.0 || B>90.0 || C>90.0)
cout << "The triangle is OBTUSE ANGLED" << endl;
cout << "The angles are:" << endl << endl;
cout << "A = " << A << " degrees" << endl;
cout << "B = " << B << " degrees" << endl;
cout << "C = " << C << " degrees" << endl;
cout << endl << "Where A,B,C stand for angles opposite to sides with the "
<< "lengths of " << a << " cm, " << b << " cm, " << c
<< " cm respectively" << endl << endl;
}
|