Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#ifndef POINTER _ H #define POINTER _ H #include #include #include / / / / Structure definitions and function pointer typedefs / / typedef double
#ifndef POINTERH
#define POINTERH
#include
#include
#include
Structure definitions and function pointer typedefs
typedef double areafnvoid shape; Function pointer type
for area functions
typedef double perimeterfnvoid shape; Function pointer
type for perimeter functions
typedef struct
struct
areafn area; Area function for shape
perimeterfn perimeter; Perimeter function for shape
virtualfunctable; Table of function pointers for the
emulated virtual functions
const char name; Name of shape
unsigned int edges; Number of edges
shapet; Generic base class for a shape
typedef struct
shapet shape; Include the base class at the start of a
specific type of shape
double width;
double length;
rectanglet;
typedef struct
shapet shape; Include the base class at the start of a
specific type of shape
double length; Length of equilateral triangle edge
trianglet;
Function pointer type for shape comparison functions
Returns if shape is less than shape
Returns if shape is greater than shape
Returns if shape is equal to shape
typedef int comparefnshapet shape shapet shape;
typedef struct linkedlistnode
shapet shape; Shape associated with the node
struct linkedlistnode next;
linkedlistnodet;
typedef struct
comparefn compare; Shape comparison function
linkedlistnodet head;
linkedlistt;
typedef struct treenode
shapet shape; Shape associated with the node
struct treenode left; Left subtree
struct treenode right; Right subtree
treenodet;
#define MAXDEPTH
typedef struct
treenodet curr; Pointer to the current node
unsigned int depth; Current depth in the tree root is at
depth
treenodet parentsMAXDEPTH; Pointer to parent nodes
treeiteratort; Helper struct for iterating through a tree
represents a current location within the tree
typedef double foreachfnshapet shape, double data;
Function pointer type for functions being run foreach shape in a
linked list
Shape functions
Returns the area of a shape
static inline double shapeareashapet shape
return shapevirtualfunctable.areashape;
Returns the perimeter of a shape
static inline double shapeperimetershapet shape
return shapevirtualfunctable.perimetershape;
Returns the name of a shape
static inline const char shapenameshapet shape
return shapename;
Returns the number of edges in a shape
static inline unsigned int shapeedgesshapet shape
return shapeedges;
Prints info about a shape
static inline void shapeprintshapet shape
printfs: area f perimeter f edges d
shapenameshape shapeareashape shapeperimetershape
shapeedgesshape;
double rectangleareavoid shape;
double triangleareavoid shape;
double rectangleperimetervoid shape;
double triangleperimetervoid shape;
void rectangleconstructrectanglet shape, const char name,
double width, double length;
void triangleconstructtrianglet shape, const char name,
double length;
int comparebyareashapet shape shapet shape;
int comparebyperimetershapet shape shapet shape;
Linked list functions
void linkedlistinitlinkedlistt list, comparefn compare;
void linkedlistinsertlinkedlistt list, linkedlistnodet
node;
void linkedlistremovelinkedlistt list, shapet shape;
Tree iterator functions
void treeiteratorbegintreeiteratort iter, treenodet
root;
void treeiteratornexttreeiteratort iter;
bool treeiteratoratendtreeiteratort iter;
treenodet treeiteratorgetnodetreeiteratort iter;
shapet treeiteratorgetshapetreeiteratort iter;
Tree analysis functions
void maxminavgareatreenodet root, double max, double
min, double avg;
double foreachtreenodet root, foreachfn func, double data;
#endif POINTERH
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started