Question: Help please. Consider the following structures. The dparrays in these structures are NOT arrays of references they are allocated dparrays with every member also individually

Help please.

Consider the following structures. The dparrays in these structures are NOT arrays of references they are allocated dparrays with every member also individually allocated.

typedef struct {

char *name;

int commonality;

int weight;

} monster;

typedef struct {

char *name;

char *description;

double area;

// allocated

// allocated

// allocated

int nmonsters;

monster **monsters;

} region;

typedef struct {

char *name;

double diameter;

int nregions;

region **regions;

} planet;

// fully allocated, NOT a reference array

// allocated

// fully allocated, NOT a reference array

Write the following functions:

/* Frees monster m and its contents. */

void dispose_monster(monster *m); // Worth 5 points

/* Frees region r and its contents, including all monsters in its monsters dparray. This may (and should) call dispose_monster(). */

void dispose_region(region *r); // Worth 10 points

/* Frees planet p and its contents, including all regions in its regions dparray. This may (and should) call dispose_region(). */

void dispose_planet(planet *p); // Worth 10 points

/* Adds a new monster to region r. You may assume the existence of the function: monster *new_monster(char *name, int commonality, int weight); Hint: The realloc() function can make your life much easier. */

void add_monster_to_region(region *r, char *mname, // Worth 10 points int mcommonality, int mweight);

/* Deletes a region from planet p. Fails silently, but does not cause an error, if the named region is not on planet p. This may (and should) call dispose_region(). */

void delete_region_from_planet(planet *p, char *rname); // Worth 15 points

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!