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 that

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.
// DO NOT INCLUDE ANY OTHER LIBRARIES/FILES
// Returns the area of a rectangle
// The shape is guaranteed to be a valid rectangle
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;
}
//using C

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

More Books

Students also viewed these Databases questions

Question

Why might some employees not want their jobs enriched?

Answered: 1 week ago

Question

3. Was escalation of commitmelll involved in making the decision?

Answered: 1 week ago

Question

Identify possible reasons for ineffective performance.

Answered: 1 week ago

Question

Describe the components of a needs assessment.

Answered: 1 week ago

Question

Describe the benefits of employee orientation.

Answered: 1 week ago