Write and test the following computeTriangle() function that returns the area a and the
perimeter p of the triangle with given side lengths a, b, c:
void computeTriangle( float&, float&, float, float, float);
#include<iostream>
#include<cmath>
using namespace std;
void computeTriangle(float&, float&, float, float, float);
int main(){
cout<<"Testing computeTriangle() function\n";
float perimeter, a, b, area, c;
cout<<"Enter the side a\n";
cin>>a;
cout<<"Enter the side b\n";
cin>>b;
cout<<"Enter the side c\n";
cin>>c;
computeTriangle(area, perimeter, a, b,c);
cout<<"Area is: "<<area<<"\nPerimeter is: "<<perimeter<<endl;
}
void computeTriangle(float &area, float&perimeter, float a, float b, float c){
perimeter = a+ b+c;
float s = perimeter / 2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
}
Comments
Leave a comment