Question: Shape functions : These functions serve to introduce the concept of polymorphism and object - oriented programming. You will be programming two types of objects

Shape functions : These functions serve to introduce the concept of polymorphism and object-oriented programming. You will be programming two types of objects that represent shapes. The rectangle_t type represents a rectangle shape with a width and length. The triangle_t type represents an equilateral triangle with a length. Both types are based on a base shape_t type that corresponds to the base class in an object-oriented language.
oriented programming. You will be programming two types of objects that represent shapes. The rectangle_t type represents a rectangle shape with a width and length. The triangle_t type represents an equilateral triangle with a length. Both types are based on a base shape_t type that corresponds to the base class in an object-oriented language.Shape functions: an object-oriented language.double rectangle_area(void* shape)
{
rectangle_t* rectangle =(rectangle_t*)shape;
// IMPLEMENT THIS
return 0;
}
// Returns the area of an equilateral triangle
// The shape is guaranteed to be a valid triangle
// The area of an equilateral triangle is sqrt(3)/4 times length squared
double triangle_area(void* shape)
{
triangle_t* triangle =(triangle_t*)shape;
// IMPLEMENT THIS
return 0;
}
// Returns the perimeter of a rectangle
// The shape is guaranteed to be a valid rectangle
double rectangle_perimeter(void* shape)
{
rectangle_t* rectangle =(rectangle_t*)shape;
// IMPLEMENT THIS
return 0;
}
// Returns the perimeter of an equilateral triangle
// The shape is guaranteed to be a valid triangle
double triangle_perimeter(void* shape)
{
triangle_t* triangle =(triangle_t*)shape;
// IMPLEMENT THIS
return 0;
}
// Initializes a rectangle shape
void rectangle_construct(rectangle_t* shape, const char* name, double width, double length)
{
// IMPLEMENT THIS
}
// Initializes a triangle shape
void triangle_construct(triangle_t* shape, const char* name, double length)
{
// IMPLEMENT THIS
}
// Compares the area of shape1 with shape2
// Returns -1 if the area of shape1 is less than the area of shape2
// Returns 1 if the area of shape1 is greater than the area of shape2
// Returns 0 if the area of shape1 is equal to the area of shape2
int compare_by_area(shape_t* shape1, shape_t* shape2)
{
// IMPLEMENT THIS
return 0;
}
// Compares the perimeter of shape1 with shape2
// Returns -1 if the perimeter of shape1 is less than the perimeter of shape2
// Returns 1 if the perimeter of shape1 is greater than the perimeter of shape2
// Returns 0 if the perimeter of shape1 is equal to the perimeter of shape2
int compare_by_perimeter(shape_t* shape1, shape_t* shape2)
{
// IMPLEMENT THIS
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!