Write a program to do the following in C The area of an arbi

Write a program to do the following in C++

The area of an arbitrary triangle can be computed using the formula

area = sqrt(s(s-a)(s-b)(s-c))

where a, b, and c are lengths of the sides, and s is the semiperimeter.

S = (a + b + c)/2

Write a void function that uses five parameters: three value parameters that provide the lengths of the edges, and computes the area and perimeter (not the semiperimeter) via reference parameters. Make your function robust. Note that not all combinations of a, b, and c produce a triangle. Your function should produce correct results for legal data and reasonable results for illegal combinations.

Use two value-return functions to perform the above. Use one to compute the area and one to compute the perimeter.

Solution

// C++ code area and perimeter of triangle

#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <stdlib.h>   
#include <math.h>

using namespace std;

void result ( double a, double b, double c, double *traingleArea, double *trianglePerimeter)
{
   double sp;
  
    if( (a >= (b+c)) || (b >= (a+c)) || (c >= (b+a)) )
    {
      cout<<\"Triangle is not possible\ \";
      exit(1);
    }

   sp = (a + b + c)/ 2.0;

   *traingleArea = sqrt (sp*(sp-a)*(sp-b)*(sp-c));

   *trianglePerimeter=a+b+c;
}


int main()
{
double traingleArea,trianglePerimeter,a,b,c;

cout << \"Input a: \";
cin >> a;
cout << \"Input b: \";
cin >> b;
cout << \"Input c: \";
cin >> c;

result(a,b,c,&traingleArea,&trianglePerimeter);


cout << \"Area: \" << traingleArea << \"\\tPerimeter: \"<<trianglePerimeter<< endl;

return 0;
}

/*
output:

Input a: 3
Input b: 4
Input c: 5
Area: 6 Perimeter: 12


Input a: 1
Input b: 3
Input c: 8
Triangle is not possible

*/

Write a program to do the following in C++ The area of an arbitrary triangle can be computed using the formula area = sqrt(s(s-a)(s-b)(s-c)) where a, b, and c a
Write a program to do the following in C++ The area of an arbitrary triangle can be computed using the formula area = sqrt(s(s-a)(s-b)(s-c)) where a, b, and c a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site