Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ineed 4 function is the function monster* makeMonster, monster** readMonsters,region** readRegions ,trainer* loadTrainers. and please i need readregion function is Important without creatregion. where is
ineed 4 function is the function
monster* makeMonster, monster** readMonsters,region** readRegions ,trainer* loadTrainers. and please i need readregion function is Important without creatregion.
where is the function region** readRegions
Problem: The Monster Trainers Need Your Help Several small monster trainers have come to you for advice reganding expeditions they'te planning into various regions. You are writing a program to estimale hew many monsters thcy can expect to capture in each negion. - 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 rolative commonality will change region by region as calculations are performed - we'll sbow you how that works shortly.) - You've also got an attas that tells you about the relevant regions asd which small monsters are present in them. - Each trainer tells you which regions they're visiting, and hew many monsten they intend so capture per region. - To estimate the number of a given monster M, a trainer will copture in a region R : Divide the relative population of M in R by R 's total relative pepulation. Multiply the result by the sotal number of captures the trainer intends per region. Round this result to the nearest integer. 5 rounds up, so yoe can use round0 and its friends. Note that this can result in a fotal slighely different than the trainer intended! Data Structures The structures youll use for the monsters, regions. itineraries and trainers are shown in the sidebar. You ma\& ase shese structures in your cede. However, you are free to add more structures if you nond. (Some of my anit test case dleponds an this structure and members and yow should net change she structwre: name and arember name) You'll ned to allocate, read, compute upon, output from, and subsequently free: - The monser inder. - The region atlas. The input will be taken from in.rxt fite. There are blank lines in the sample inputs to make them more readable, They may or may not be present in the actual inputs; you should completely ignore blank lines. If you use frcanf, those blank lines will be automatically ignored. You can just write your code thinking that the line gaps do not exist. The first line of the file contains the number of monsters mcotint and the word moasters just as an indication that this number is count of monsters. You can read that string and ignore it. The next meosurt lines contain information of monsters where each line contains two strings and one integer. The first string is the monster name (single word string with maximum length is 50 ). The second string is the element of the monster (single word string with maximum length is 50). The integer represents the population of the monster (max value is 1milliob) After that the file contains the number of regions rcoumt and the word regions. You can read the word regions and ignore it. After that the file contains information about rcosh number of regions. Where the first line of a region contains the name of the region, next line contains the number of different monsters rmcovert in that region with the word monsters. The next rmcount lines contain the name of different monsters in the region. After the rcount number of regions, the file contains number of trainers feouat and the word Trainers. Then teount number of trainers' information is provided. For each trainer the first line represents the trainer name (single word string with maximum length is 50), the next line contains how many captures with the word captures and then then next line contains number regions trcount with the word regions. After that the trcoumt lines contain the name of the region the trainer is visiting Output Specification The cotput of the program must be written to out.txi file with exact same format as apecified in the sample output. The output also need to be displayed in the console. The output contains each trainer name with the number of monster the trainer will capture from each region. Follow the output format as shown in the sample output. Note that we will test your code with diff command to anatch your output file with our output file. If they do not exactly match. you will loss significant grade for that specific test case. But there maybe some partial credit depending on how much it is not matching. Print order should generally be consistent with input: - Print the trainers in the order you got them. - Within the trainers, print the regions in the order you got the visits. - Within the regions, print the monster counts in the order they show up in the atlas for that region. - Print blank lines between each trainer. trainer* readirainers(FILE* infile, int *trainercount, region** regionlist, int countRegions): This function retums a dynamically allocated array of trainers, filled up with the information from the tile, and the trainer's visits filed 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 readRegions 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 process_inputs(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 release_nemory(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 Finclude "leak_detector_c.h in your code, and You must call atexit(report_mem_Ieak) 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. Rubric (subject to change): According to the Syllabus, the code will be compiled and tested in Mimir Platform for grading. If your code does niot compile in Mimir, we conclude that your code is not compiling and it will be graded accordingly. We will apply a set of test cases to check whether your code can produce the expected output or not. Failing cach test case will reduce some grade based on the rubric given bellow. If you hardcode the output, you will get 200% for the assignment. 1. If a code does not compile the code may get 0 . However, some partial credit maybe awarded. A code having compiler error cannot get more than 50% even most of the codes are correct 2. If you modify or do not use the required structure: 0 3. Not using dynamic memory allocation for storing data will receive 0 4. There is no grade for a well indented and well commented code. But a bad indented code will receive 20% penalty. Not putting comment in some important block of code 10% 5. Implementing required functions and other requirements: 30% 6. Freeing up memory properly with zero memory leak (if all the required malloc implemented): (20%) 7. Passing test cases: 50% Example Input and Output Example Input Example Output (sce the mapping cxample 8 moasten StAugutiae Orass 12 discussed in the next page to understand how Zoysia Grass 8 this output is generated) WholeWheat Bread 6 Alice MuloGinaia Breal 10 Ryc Brcal 10 Cimaman Spice 5 Pepper Spice 10 Punpian Spice 30 Ronse 3 regiven 25 Aapeatine 1 Zoyna 1 Whelewheat 1 Pepeer Aria 1 Zeyaia 1 Mukicirain Rome 1 Pepper 4 moaven 2 Pampkin StAugastine Zoysus Wholcwbein Pepper Bob Frome Helve5measters1Zoywia1wbeleWheit 5 monsters 1 Pepper Multionin 1 Whelewheut Rye Cimumion I Rye Ara Aria5moastenZoysiaMultionain17oysia1Mukictrair:1Pepper2Pamplin Cimamen Pepper Pumphia 3 Tranern Alice 5 eaplures 2 regison Rome Aria Bob 4 captures 3 reghises Rome Helve Aria Carol 10 captires I fegioa AriaStep 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