In C The following function accepts objects by reference and
(In C++) 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.
Solution
I\'m not aware of the classes created in Question 1.
However I can define the functions that better suits the provided requirements.
I\'m assuming that there is a Shape class, Circle class and a Triangle class
PROGRAM:
#include <iostream>
using namespace std;
class Shape{
public:
float area;
float perimeter;
Shape()
{
area = 0;
perimeter = 0;
}
float getArea()
{
return area;
}
float getPerimeter()
{
return perimeter;
}
};
class Triangle: public Shape{
public:
float side1, side2, base, height;
Triangle( float a=0, float b=0, float c=0, float d=0){
side1 = a;
side2 = b;
base = c;
height = d;
}
float calcPerimeter()
{
perimeter = side1 + side2 + base;
}
float calcArea()
{
area = 0.5*base*height;
}
float display()
{
cout<< \"This Triangle has a perimeter of: \"<<getPerimeter()<<\" and an area of: \"<<getArea()<<\"\ \";
}
};
class Circle: public Shape{
public:
float radius;
Circle( int a=0)
{
radius = a;
}
float calcPerimeter()
{
perimeter = 2*3.14*radius;
}
float calcArea()
{
area = 3.14*radius*radius;
}
float display()
{
cout<< \"This circle has a perimeter of: \"<<getPerimeter()<<\" and an area of: \"<<getArea()<<\"\ \";
}
};
// The larger Area function
void largerArea(Shape &a, Shape &b, double *result)
{
if(a.area > b.area)
*result = a.area;
else
*result = b.area;
}
int main() {
// Creating object for circle class
Circle circle(3.1);
circle.calcArea();
circle.calcPerimeter();
circle.display();
//creating object for triangle class
Triangle triangle(2,3,4,6);
triangle.calcArea();
triangle.calcPerimeter();
triangle.display();
double result = 0.0;
//function call to larger Area
largerArea(circle, triangle, &result);
cout<<\"The larger area is: \"<<result;
return 0;
}
OUTPUT:
This circle has a perimeter of: 18.84 and an area of: 28.26
This Triangle has a perimeter of: 9 and an area of: 12
The larger area is: 28.26

