Beruflich Dokumente
Kultur Dokumente
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
using namespace std;
/**
* determines whether three numbers satisfies the triangle
* inequality; that is, can form the sides of a triangle.
* @param num1 a non-negative fixed-point value
* @param num2 a non-negative fixed-point value
* @param num3 a non-negative fixed-point value
* @return true if these numbers satisfy the triangle
* inequality; otherwise, false is returned. Also returns
* false if any of the numbers is non-positive.
*/
bool isTriangle(double num1, double num2, double num3)
{
bool status;
if(num2+num3 > num1 && num1+num3 > num2 && num1+num2 >
num3)
{
status = true;
}
else
{
status = false;
}
return status;
}
/**
* determines whether a triangle is a right-triangle
* @param sideA the length of the first side of the triangle
* @param sideB the length of the second side of the triangle
* @param sideC the length of the third side of the triangle
* @return true if the sum of squares of the lengths of two sides
* is equal to the third side; otherwise, false is returned.
*/
bool isRight(double sideA, double sideB, double sideC)
{
bool status;
/**
* determines whether a triangle is an equilateral triangle
* @param sideA the length of the first side of the triangle
* @param sideB the length of the second side of the triangle
* @param sideC the length of the third side of the triangle
* @return true if the sides are equal; otherwise,
* false is returned.
*/
bool isEquilateral(double sideA, double sideB, double sideC)
{
bool status;
/**
* determines whether a triangle is a scalene triangle
* @param sideA the length of the first side of the triangle
* @param sideB the length of the second side of the triangle
* @param sideC the length of the third side of the triangle
* @return true if no two sides have the same lengths;
* otherwise, false is returned.
*/
bool isScalene(double sideA, double sideB, double sideC)
{
bool status;
/**
* computes the area and perimeter of a triangle
* @param sideA the length of the first side of the triangle
* @param sideB the length of the second side of the triangle
* @param sideC the length of the third side of the triangle
* @param perimeter the perimeter of the triangle
* @param area the area of the triangle using Herron’s formula.
*/
void calcTriangle(double sideA, double sideB, double sideC, double&
perimeter, double S, double& area)
{
perimeter=sideA+sideB+sideC;
S=perimeter/2;
area=sqrt(S*(S-sideA)*(S-sideB)*(S-sideC));
}
int main()
{
double num1, num2, num3;
double sideA, sideB, sideC, perimeter, area, S;
string triple;
fstream inFile;
cout<<endl;
cout<<"Enter the name of the data file> ";
cin>>triple;
inFile.open("triple.in",ios::in);
if (inFile.fail())
{
cout<<"Unable to open triple.in for input."<<endl;
return 1;
}
cout<<endl;
cout<<" Triangle Program Report "<<endl;
cout<<"================================="<<endl;
while (inFile>>sideA)
{
inFile>>sideB>>sideC;
}
else
{
cout<<setprecision(3)<<"*** "<<sideA<<", "<<sideB<<",
"<<sideC<<" cannot form the sides of a triangle ***"<<endl;
}
cout<<"---------------------------------"<<endl;
}
cout<<"*** END OF REPORT ***"<<endl;
cout<<"================================="<<endl;
cout<<endl;
inFile.close();
return 0;
}