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
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
string validity(double, double, double);
void classification(double, double, double, string &t, string& k);
string classi(double, double, double);
string kind(double, double, double);
int main()
{
double a,b,c;
double x=0,y=0;
ifstream infile;
ofstream outfile;
outfile.open("output.txt");
infile.open("input.txt");
outfile << "Angle 1 Angle 2 Angle3 Status Type Kind" << endl;
while(!infile.eof())
{
infile >> a >> b >> c;
string i = validity(a,b,c);
string t, k;
classification(a, b, c, t, k);
outfile << a << setw(15) << b << setw(10) << c <<setw(10) << i << setw(13) << t << setw(15) << k << endl;
if(i=="Valid")
x++;
else
y++;
}
outfile <<"Valid Triangles: " << x << "\n" <<"Inavlid Triangles: " << y << endl;
infile.close();
outfile.close();
return 0;
}
//checks for valid triangles
string validity(double a, double b, double c)
{
string i;
if (a<0 || b<0 || c<0 || a+b+c==180)
i="Valid";
else
i="Invalid";
return i;
}
//classifys the triangle
void classification(double a, double b, double c, string &t, string &k)
{
t = classi(a,b,c);
k = kind(a,b,c);
}
string classi(double a, double b, double c)
{
string t;
if(a==b && b==c && a==c)
t="equalaterial";
else if(a==b || b==c || a==c)
t="isosceles";
else
t="scalene";
return t;
}
string kind(double a, double b, double c)
{
string k;
if(a==90 || b==90 || c==90)
k="right";
else if(a>90 || b>90 || c>90)
k="obtuse";
else
k="acute";
return k;
}
|
Angle 1 Angle 2 Angle3 Status Type Kind
2 24 2 Invalid isosceles acute
60 60 60 Valid equalaterial acute
30 30 30 Invalid equalaterial acute
30 30 30 Invalid equalaterial acute
Valid Triangles: 1
Inavlid Triangles: 3 |