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
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
//Function Prototypes
int read(int);
int triangle(int, int, int);
void write(int,int,int,ofstream&);
void printheader(ofstream&);
//File I/O
ifstream inf("Triangle.in");
ofstream out("Triangle.out");
void printheader(ofstream& out)
{
out << "\tTriangle Program\n"
<< " Angles of the Triangle \t Type of Triangle\n";
}
int read(ifstream& inf)
{
int a;
inf >> a;
return a;
}
int triangle(int a, int b, int c)
{
if(((a+b)>c) || ((c+b)>a) || ((c+a)>b))
out << endl << "Valid Triangle";
else
out << endl << "Not a Right Triangle";
}
void right(int a, int b, int c)
{
if(pow(c,2) == (pow(a,2) + pow(b,2)))
out<<endl<<"This is a right triangle";
else
{
out<<endl<<"This is not a right triangle";
triangle(a,b,c);
}
}
void acute(int a, int b, int c)
{
if(pow(c,2) < (pow(a,2) + pow(b,2)))
out << endl << "Acute Triangle";
else
{
out << endl << "Not Acute";
triangle(a,b,c);
}
}
void obtuse(int a, int b, int c)
{
if(pow(c,2) > (pow(a,2) + pow(b,2)))
out << endl << "Obtuse Triangle";
else
{
out << endl << "Not Obtuse";
triangle(a,b,c);
}
}
int LARGEST(int a, int b, int c)
{
return max(max(a,b),c);
}
void write(int a, int b, int c, ofstream& out)
{
out << " " << a << " x " << b << " x " << c
<< " " << triangle(a,b,c) << endl;
}
int main()
{
int a, b, c,valid,right,acute,obtuse;
printheader(out);
while(!inf.eof())
{
c=LARGEST(a,b,c);
a=read(inf);
b=read(inf);
c=read(inf);
valid=triangle(a,b,c);
right(a,b,c);
acute(a,b,c);
obtuse(a,b,c);
write(a,b,c,out);
}
return 0;
}
|