Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with the problem in C. (Do it without FILE I/O please) Details Several small monster trainers have come to you for advice regarding

Need help with the problem in C. (Do it without FILE I/O please)

image text in transcribedimage text in transcribedimage text in transcribed

Details Several small monster trainers have come to you for advice regarding expeditions they're planning into various regions. You are writing a program to estimate how many monsters of each type they can expect to capture in each region. - You've got a Small Monster Index that tells you the name, type, and relative commonality of all the small monsters in question. (A monster's absolute commonality is the same in each region. A monster's relative commonality will change region by region as calculations are performed - we'll show you how that works shortly.) - You've also got an atlas that tells you about the relevant regions and which small monsters are present in them. - Each trainer tells you which regions they're visiting, and how many monsters they intend to capture per region. - To estimate the number of a given monster M a trainer will capture in a region R : Divide the relative population of M in R by R 's total relative population. Multiply the result by the total number of captures the trainer intends per region. Round this result to the nearest integer. .5 rounds up, so you can use round() and its friends. Note that this can result in a total slightly different than the trainer intended! in Specific Requirements - You have to use dynamic memory allocation - You have to use the provided structures without changing their name - You may not use global variables - You are not allowed to use VLA - You are not allowed to create same monster and regions multiple times. Try to find a technique to re-use the created monsters and regions. - You have to implement at least the following functions: - monster* makeMonster(char *name, char *element, int population): This function returns a dynamically allocated monster filled with the provided parameters - monster** readMonsters(int *monstercount): This function returns an array of monster pointers where each monster pointer points to the dynamically allocated monsters with fill-up information from the provided inputs. It can use the makeMonster function in this process. This function also updates the passed variable reference pointed by monsterCount so that the caller to this function knows how many monsters are returned from the function. - region** readRegions(int *countRegions, monster** monsterlist, int monstercount): This function returns an array of region pointers where each region pointer points to a dynamically allocated region, filled up with the information from the inputs, and the region's monsters member points to an appropriate list of monsters from the monsterList passed to this function. This function also updates the passed variable reference pointed by countRegions (to inform the caller about this count). As the loadMonsters function has created all the monsters using dynamic memory allocation, you are getting this feature to use/reuse those monsters in this process. - trainer* loadTrainers(int *trainerCount, region** regionList, int countRegions): This function returns a dynamically allocated array of trainers, filled up with the information from the inputse, and the trainer's visits field points to a dynamically allocated itinerary which is filled based on the passed regionList. This function also updates the passed variable reference pointed by trainerCount. As the loadRegions function has crated all the regions using dynamic memory allocation, you are getting this feature to use/re-use those regions in this process. - void processinputs(monster** monsterlist, int monstercount, region** regionList, int regionCount, trainer* trainerList, int trainerCount ): This function processes all the data and produce the output. During this process, you can create/use more functions if you want. - void releaseMemory(monster** monsterList, int monsterCount, region** regionList, int regionCount, trainer* trainerList, int trainerCount ): This function takes all the dynamically allocated arrays and free-up all the memory. You can create/use more function in this process if you want. - You have to use memory leak detector code as shown the lab as well as explained in webcourses - You must \#include "leak_detector_c.h" in your code, and - You must call atexit(report_mem_leak) as the first line of your main(). - leak_detector_c.h and leak_detector_c.c are available in webcourse. - You do not need to comment line by line, but comment every function and every "paragraph" of code. - You don't have to hold any particular indentation standard, but you must indent and you must do so consistently within your own code

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

Group Size and Communication

Answered: 1 week ago

Question

Understanding Group Roles

Answered: 1 week ago