Question: Magic Inventory Assessment Due: 1 1 : 5 9 pm on September 6 th , 2 0 2 4 Objectives Give additional practice with loops
Magic Inventory Assessment
Due: :pm on September th
Objectives
Give additional practice with loops in C
Give additional practice with arrays in C
Give additional practice implementing functions in C
Give additional practice with structs in C
Give additional practice with strings in C
Give practice with dynamic memory allocation and management in C
Story
As the trusted magic resource archmage of the Great Oak School of Magic you are responsible for
determining the amount of magic consumed by your school. Failure to use the proper amount of
magic can lead to worldaltering disaster You are now spearheading project Magical Inventory
Assessment MIA
You are organizing and generalizing the information recorded by the school to ensure there
are no cataclysm. Every person in the school has a role to fulfill. You have noted which magical
materials are needed by each role. Currently, every magical material requires some amount of
magic.
As time goes on magical advancements enable making material using a different amount of
magic. Additionally, some roles might require a different amount of magical materials. You want
to ensure that after each change, the required total amount of magic needed is known.
Problem
Create a program that takes in an initial set of roles, magical material requirements for roles, and
magic requirements for magical materials. The program should then take in updates that include:
changing the magic requirement of a magical material, adding an existing magical needed by a
role, removing a magical material needed by a role, or changing the number of magical material
needed by a particular role. With each change, your program should quickly determine the new
total magic required by your school.
we all remember what happened to Cyre...
Input Specification
Your input will consist of multiple parts. Below is the layout of the input in the order they will
be entered,
A single line containing integer, N N representing the number of roles
at the school.
The next N lines, the ith of which starts with an integer, Ki Ki
representing the number of magical materials needed by the ith role. That same line will
have Ki space separated pairs of tokens. The first token of the pair of tokens will a string
of upper and lowercase characters, s representing the name of the magical material. The
second token of the pair will be an integer, a a representing the amount of
that particular magical material needed.
The line will contain pairs of tokens. The every token will be separated by a space. There
will be no extra spaces after the last token. The token pairs will be a string s representing
the name of a magical material and an integer, b b representing the amount
of magic needed for the magical material with name s
It is guaranteed that every material needed by all roles will exist in this list. Each name of
a magical material will be at most characters.
The next line will contain a single integer, D D representing the number
of denizens of the Great Oak School of Magic.
The following line will contain D integers, the ith of which, ci ci N represents the
role of the ith citizen.
The following line will contain a single integer, U U representing the
number of updates.
The following U lines will each describe an update. Each update will be one of the following
forms.
m x Change the magic requirement of magical material m to x
x ; m will be a string from the list of magical materials
r m a Role r now needs a amount of magical material m You will be guaranteed
that role r requires at least of item m before the update.
r N ; a ; m will be a string from the list of magical materials
Output Specification
Your program should output for each update a single line containing an integer. The value on the
line should be the total amount of magic required by everyone in the Great Oak School of Magic
after the corresponding update. Your program will not print the initial magic required.
Example Input Output
Below is are example of cases that your program will be tested against. The below cases are not
meant to be extensive. It is your responsibility. You should work on developing your own cases.
Input Output
QuickSilver Resin
Resin GraveDust
QuickSilver Resin GraveDust
Resin
Resin
GraveDust
QuickSilver
Plutonium
Plutonium
Plutonium
Plutonium
Example Explanation
Sample Case
The first case has roles.
The first role needs magical material of type QuickSilver and magical material of type
Resin.
The second role needs magical material of type Resin and magical materials of type
GraveDust.
T
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
