Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

Define Scientific Management

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago