Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This assignment is intended to make you do a lot of work with dynamic memory allocation, pointers, and arrays of pointers. Don't wait until the
This assignment is intended to make you do a lot of work with dynamic memory allocation, pointers, and arrays of pointers. Don\'t wait until the weekend it\'s due to start it! Your solution should follow a set of requirements to get credit. What should you submit? Write all the code in a single file main.c file. Submit your main.c file only. Please include the following commented lines in the beginning of your code to declare your authorship of the code: /* COP 3502C Assignment 1 This program is written by: Your Full Name */ Compliance with Rules: UCF Golden rules apply towards this assignment and submission. Assignment rules mentioned in syllabus, are also applied in this submission. The TA and Instructor can call any students for explaining any part of the code in order to better assess your authorship and for further clarification if needed. Caution!!! Sharing this assignment description (fully or partly) as well as your code (fully or partly) to anyone/anywhere is a violation of the policy. I may report to office of student conduct and an investigation can easily trace the student who shared/posted it. Also, getting a part of code from anywhere will be considered as cheating. Deadline: See the deadline in Webcourses. The assignment will accept late submission up to 24 hours after the due date time with 20% penalty. After that the assignment submission will be locked. An assignment submitted by email will not be graded and such emails will not be replied according to the course policy. What to do if you need clarification on the problem? I will create a discussion thread in webcourses and I highly encourage you to ask your question in the discussion board. Maybe many students might have same question like you. Also, other students can reply and you might get your answer faster. Also, you can write an email to the TAs and put the course teacher in the cc for clarification on the requirements. How to get help if you are stuck? According to the course policy, all the helps should be taken during office hours. Occasionally, we might reply in email. Problem: Help the Monster Trainer! You are a genius programmer and learned dynamic memory allocation. Now it is time to show your expertise on this topic. Several 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 they can expect to capture in each region.
Input Specification (standard input No file I/O) Use regular scanf to take inputs. Your code should not use any file i/o, such as fopen, fscanf, etc., are not relevant for this assignment. The input will be taken from standard console input. Read the commands mentioned at the end of the assignment description to see how can you pass input to your code as the input size could be large. In the input files, there can be blank lines 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 regular scanf, 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 input contains the overall different number of monsters mcount . The next mcount 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 1 million) After that the input contains the number of regions rcount. After that the input contains information about rcount number of regions. Where the first line of a region contains the name of the region, next line contains the number of different monsters rmcount 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 input contains number of trainers tcount. Then tcount 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 trcount lines contain the name of the region the trainer is visiting. Output Specification The output of the program must be written to standard console output (no file i/o such as fprintf should be used). The output should be in the exact format as specified in the sample output. See the commands below at the end of the assignment description on how to write the result of your code into a file using command line. This will help you to compare your result with the actual result. 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 match 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:
Specific Requirements
- You\'ve got a Small Monster Index that tells you the name, type, and relative commonality of all the small monsters in question.
- 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:
- The monster index.
- The region atlas.
- A list of trainers.
typedef struct monster { | typedef struct region { | |
char *name; | char *name; | |
char *element; | int monster_cnt; | |
int population; | int total_population; monster **monsters; | |
} monster; | ||
} region; | ||
typedef struct itinerary | typedef struct trainer | |
{ | { | |
int region_cnt; | char *name; | |
region **regions; | itinerary *visits; | |
int captures; | ||
} trainer; | ||
} itinerary; |
- 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.
Rome | Raw | Divided | Alice | Round | Bob | Round | ||
Coefficient | 1.00 | 36.00 | 5.00 | 4.00 | ||||
StAugustine | 12.00 | 0.33 | 1.67 | 2.00 | 1.33 | 1.00 | ||
Zoysia | 8.00 | 0.22 | 1.11 | 1.00 | 0.89 | 1.00 | ||
WholeWheat | 6.00 | 0.17 | 0.83 | 1.00 | 0.67 | 1.00 | ||
Pepper | 10.00 | 0.28 | 1.39 | 1.00 | 1.11 | 1.00 | ||
Total | 36.00 | 1.00 | 5.00 | 5.00 | 4.00 | 4.00 | ||
Helve | Raw | Divided | Bob | Round | ||||
Coefficient | 1.00 | 43.00 | 4.00 | |||||
StAugustine | 12.00 | 0.28 | 1.12 | 1.00 | ||||
WholeWheat | 6.00 | 0.14 | 0.56 | 1.00 | ||||
MultiGrain | 10.00 | 0.23 | 0.93 | 1.00 | ||||
Rye | 10.00 | 0.23 | 0.93 | 1.00 | ||||
Cinnamon | 5.00 | 0.12 | 0.47 | 0.00 | ||||
Total | 43.00 | 1.00 | 4.00 | 4.00 | ||||
Aria | Raw | Divided | Alice | Round | Bob | Round | Carol | Round |
Coefficient | 1.00 | 63.00 | 5.00 | 4.00 | 10.00 | |||
Zoysia | 8.00 | 0.13 | 0.63 | 1.00 | 0.51 | 1.00 | 1.27 | 1.00 |
MultiGrain | 10.00 | 0.16 | 0.79 | 1.00 | 0.63 | 1.00 | 1.59 | 2.00 |
Cinnamon | 5.00 | 0.08 | 0.40 | 0.00 | 0.32 | 0.00 | 0.79 | 1.00 |
Pepper | 10.00 | 0.16 | 0.79 | 1.00 | 0.63 | 1.00 | 1.59 | 2.00 |
Pumpkin | 30.00 | 0.48 | 2.38 | 2.00 | 1.90 | 2.00 | 4.76 | 5.00 |
Total | 63.00 | 1.00 | 5.00 | 5.00 | 4.00 | 5.00 | 10.00 | 11.00 |
- 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:
- You have to use memory leak detector code as shown the lab as well as explained in webcourses o You must #include \"leak_detector_c.h\" in your code, and
- You do not need to comment line by line, but comment every function and every paragraph of code.
- You dont have to hold any particular indentation standard, but you must indent and you must do so consistently within your own code.
- 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
- If you modify or do not use the required structure: get 0
- Not using dynamic memory allocation for storing data will receive 0
- 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%
- Implementing required functions and other requirements: 30%
- Freeing up memory properly with zero memory leak (if all the required malloc implemented): (20%)
- Passing test cases: 50%
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