Question: in c The program you re writing will facilitate distributing a budget among multiple departments. Each department has a list of items they wish to
in c The program youre writing will facilitate distributing a budget among multiple departments.
Each department has a list of items they wish to purchase and youll simulate a simple algorithm
to determine which items are purchased.
Input File Format
Reminder you can open a file to read from by doing the following:
Open the fileName
FILE f fopen fileName, r;
if fNULL
printfERROR Invalid file s
fileName;
exit;
The input file will list the department followed by the namesprices of the items this depart
ment desires. Here is the generic format the input files will follow:
Each string will contain no space chars and will have a length of at most characters not
including the NULL terminator The prices will be doubles. Heres a simple example input file:
Mathematics
GraphPaper
Coffee
Algorithm for Distributing the Budget
Each department is given an initial priority of This priority will represent the total amount
of money spent on that department so far. Each time an item is purchased youll update
that priority accordingly.
Add to each departments list of itemsDesired the items they have requested in their re
spective files.
Add each department to a priority queue.
While the remaining budget is do the following:
Remove and save the front department of the priority queue.
While the price of the next item desired by this department is the remaining budget,
move that item to the departments itemsRemoved list.
if there are no desired items in this departments itemsDesired list, then they are given
a scholarship equal to $ or the remaining the budget whichever is smaller
Otherwise, the next desired item is purchased for this department.
In either case, remember to:
Update the priority of the department
Add the item to their list of itemsReceived list
Add this department back to the priority queue
Deduct the amount spent from the remaining budget
Output
Your output will start with an list of the items in the order which they were purchased including
their prices and which department they were purchased for
ITEMS PURCHASED
After, the above you should list of the departments with the items they received and the ones
they did not receive be sure to also print remaining items in the itemsDesired list Youll
also list the total amount of money spent on the specific department and what percentage of the
total budget that is
Total Spent $
Percent of Budget
ITEMS RECEIVED
ITEMS NOT RECEIVED
Total Spent $
Percent of Budget
ITEMS RECEIVED
ITEMS NOT RECEIVED
Total Spent $
Percent of Budget
ITEMS RECEIVED
ITEMS NOT RECEIVED
Your solutions output should match the provided sample output. To better match the sample
output, use the following partial code segments to print your prices:
Printing prices as items are purchased:
sprintf priceString, $lf your price here ;
printf "Department of s s s
department item priceString ;
Printing list of items:
sprintf priceString, $lf your price here ;
printfs s
item priceString ;
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
