联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> OS作业OS作业

日期:2024-03-24 05:01

CS2124 Data Structures

Project 1 - Priority Queue

1    Overview

The program you’re writing will facilitate distributing a budget among multiple departments. Each department has a list of items they wish to purchase and you’ll simulate a simple algorithm to determine which items are purchased.

2    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(  f==NULL  )

{

printf("ERROR  -  Invalid  file  %s\n",  fileName);

exit(-1);

}

The input file will list the department followed by the names/prices of the items this depart- ment desires. Here is the generic format the input files will follow:

<department-name-string>

<item1-name-string>

<item1-price-double>

<item2-name-string>

<item2-price-double>

....

<itemlast-name-string>

<itemlast-price-double>

Each string will contain no space chars and will have a length of at most 30 chararcters (not including the NULL terminator). The prices will be doubles. Here’s a simple example input file:

Mathematics

Graph-Paper

150

Coffee

300

3    Algorithm for Distributing the Budget

? Each department is given an initial priority of 0. This priority will represent the total amount of money spent on that department so far.  Each time an item is purchased you’ll update that priority accordingly.

? Add to each department’s 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 > 0 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 department’s itemsRemoved list.

 if there are no desired items in this department’s itemsDesired list, then they are given a scholarship equal to $1000 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

4    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

<department-name>  -  <item1-name> <department-name>  -  <item2-name> <department-name>  -  <item3-name>

...

-  <item1-price>

-  <item2-price>

-  <item3-price>

<department-name>  -  <itemlast-name>  -  <itemlast-price>

After, the above you should list of the departments with the items they received and the ones they did not receive. You’ll also list the total amount of money spent on the specific department and what percentage of the total budget that is.

<department1-name>

Total  Spent            =  $<department1-priority>

Percent  of  Budget  =  <department1-priority>/<total-budget>%

ITEMS  RECEIVED

<item1-name>       -  <item1-price>

<item2-name>       -  <item2-price>

....

<itemlast-name>  -  <itemlast-price>

ITEMS  NOT  RECEIVED

<item1-name>       -  <item1-price>

<item2-name>       -  <item2-price>

....

<itemlast-name>  -  <itemlast-price>

<department2-name>

Total  Spent            =  $<department2-priority>

Percent  of  Budget  =  <department2-priority>/<total-budget>%

ITEMS  RECEIVED

<item1-name>       -  <item1-price>

<item2-name>       -  <item2-price>

....

<itemlast-name>  -  <itemlast-price>

ITEMS  NOT  RECEIVED

<item1-name>       -  <item1-price>

<item2-name>       -  <item2-price>

....

<itemlast-name>  -  <itemlast-price>

...

<departmentlast-name>

Total  Spent             =  $<departmentlast--priority>

Percent  of  Budget  =  <departmentlast--priority>/<total-budget>%

ITEMS  RECEIVED

<item1-name>       -  <item1-price>

<item2-name>       -  <item2-price>

....

<itemlast-name>  -  <itemlast-price>

ITEMS  NOT  RECEIVED

<item1-name>       -  <item1-price>

<item2-name>       -  <item2-price>

....

<itemlast-name>  -  <itemlast-price>

Your solution’s 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,  "$%.2lf",  /*  your  price  here  */  );

printf(  "Department  of  %-30s  -  %-30s  -  %20s\n",  /*  department  */,  /*  item  */,  priceString  );

//Printing  list  of  items:

sprintf(  priceString,  "$%.2lf",  /*  your  price  here  */  );

printf(  "%-30s  -  %20s\n",  /*  item  */,  priceString  );

5    Deliverables:

Upload your resourceManagement.c file to Blackboard under Project 1.  If you created any other .c or .h files for your solution be sure to submit those as well as an updated makefile.





版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp