WRITE A C PROGRAM TO IMPLEMENT THE FOLLOWING The following f
***********WRITE A C++ PROGRAM TO IMPLEMENT THE FOLLOWING***********
The following function accepts objects by reference and indicates the result of the operation by storing a value in the variable pointed to by result. Implement the function using the classes defined in Question 1.
/**
* Determines the larger area between two Shape objects
* The larger area is stored in result
*/
void largerArea(Shape &a, Shape &b, double *result);
Your implementation belongs in a larger program, which produces the following output:
This Triangle has a perimeter of: 12 and an area of: 6
This Circle has a perimeter of: 12.5664 and an area of: 12.5664
The larger area is: 12.5664
This Triangle has a perimeter of: 24 and an area of: 24
This Circle has a perimeter of: 12.5664 and an area of: 12.5664
The larger area is: 24
Note, largerArea() must not produce terminal output, the value must be passed to the caller through the result pointer variable.
********I HAVE ALREADY STARTED THE PROGRAM(BELOW) AND JUST NEED HELP FINISHING IT**********
#include <iostream>
using namespace std;
void describeShape
int main()
{
triangle t;
circle c;
c.setDims(4);
t.setDims(3,4,5);
describeShape(t);
describeShape(c);
return 0;
}
Solution
#include <iostream>
 #include <math.h>
 using namespace std;
 #define PI 3.14
 //Class circle
 class circle
 {
 public:
 float radius;
 //Sets the radius
 void setDims(float r)
 {
 radius = r;
 }
 //Area pi*r*r
 //perimeter 2 pi r
 };
//Class Triangle
 class triangle
 {
 public:
 float aT, bT, cT, sT;
 //Sets the side of the triangle
 void setDims(int f,int s,int t)
 {
 aT = f; bT = s; cT = t;
 }
 //Area 1/2 *b *h
 //perimeter Scalene Triangle a+b+c
 };
//Class Shape
 class Shape
 {
 public:
 float areaC, periC;
 float areaT, periT;
 //Takes triangle class object and calculates the area and perimeter
 void describeShape(triangle &t)
 {
 t.sT = (t.aT + t.bT + t.cT)/2;
 t.sT = (t.sT * (t.sT - t.aT) * (t.sT - t.bT) * (t.sT - t.cT));
 areaT = sqrt(t.sT);
 periT = (t.aT + t.aT + t.cT);
 }
//Takes circle class object and calculates the area and perimeter
 void describeShape(circle &c)
 {
 areaC = PI * c.radius * c.radius;
 periC = 2 * PI * c.radius;
 }
//Find out the biggest area
 void largerArea(Shape &a, Shape &b, double *result)
 {
 if(b.areaC > a.areaT)
 *result = b.areaC;
 else
 *result = a.areaT;
 }
 };
int main()
 {
 double res;
 triangle t;
 circle c;
 Shape s1, s2;
 c.setDims(4);
 t.setDims(3,4,5);
 s1.describeShape(t);
 s2.describeShape(c);
 s1.largerArea(s1, s2, &res);
 cout<<\"\  This Triangle has a perimeter of: \"<<s1.periT<<\" and an area of: \"<<s1.areaT;
 cout<<\"\  This Circle has a perimeter of: \"<<s2.periC<<\" and an area of: \"<<s2.areaC;
 cout<<\"\  The larger area is: \"<<res;
 return 0;
 }
Output:
This Triangle has a perimeter of: 11 and an area of: 6
 This Circle has a perimeter of: 25.12 and an area of: 50.24
 The larger area is: 50.24
If c.setDims(2); t.setDims(8,9,5);
Output:
This Triangle has a perimeter of: 21 and an area of: 19.8997
 This Circle has a perimeter of: 12.56 and an area of: 12.56
 The larger area is: 19.8997



