首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
讲解CS 5/7343程序、辅导program编程语言、讲解CSS,Java程序语言 辅导Web开发|讲解数据库SQL
项目预算:
开发周期:
发布时间:
要求地区:
CS 5/7343 Spring 2021
Programming Homework 2
Due Date: 4/3 (Sat) 11:59 pm (No extensions). 5% bonus if you hand in by 3/31 (Wed) 11:59pm
The goal of the program is to provide experience on using synchronization tools (mutex) and gain some
experience on server/threadpool programming.
Application – Auctions
This program will simulate auctions. The main process will be an auctioneer which will have different
type of items (denoted by integers 1 to k) up for auction. There may be more than one item available for
auction for each type.
Customers and tables
There are a set of tables in the auction house. (Each table should have an id, similar for what you do
with the threads in program 1). Each table will sit one customer. Customers arriving will be put into a
wait queue (there is no limit on the length of the queue). For any table without a customer, it will scan
the wait queue to see if there is a customer. If there is, the table will get the customer to sit there.
Customer are assigned to tables on a first-come-first-serve basis.
Each customer has three attributes:
An ID (as an integer)
The total amount of money the customer has (as a positive integer)
A list of items that he/she is interested in, represented by a list of integers. (notice that the
customer may be interested in more than one item for a certain type, so the list of integers can
have duplicates). You can assume the list will only be of integers between 1 and k.
A customer can leave any time a round of auction has finished. However, when he/she has 0 dollars left,
he/she must leave. Also, if he/she has obtained all the items he/she is interested in, he/she must leave
immediately.
Each table is represented by a thread that is created in the beginning of the program. Once each thread
is created, it is NOT joined when a customer leaves. Rather, the thread will see if there is any customer
available on the wait queue and sit one of them if available. The thread only quits when the main
process tells it to.
Each round of auction
A round of auction starts when the auctioneer (main process) announce the next item to be auctioned.
Before the auctioneer do that, he/she check which table is occupied, and will only allow those tables
that are occupied at that time to take part in that round of auction.
Each customer will then check whether he/she is interested in the item. Then he/she will bid a random
amount (not more than the amount of money he/she has). A customer will bid 0 if he/she has no
interest in the item. Any bidding amount must be an integer.
If no one bid, the auction ends and the item is discarded.
If only one customer bids, the auction ends immediately and the customer that bid will win the item.
However, if more than one customer bids, then any customer that bids will be allowed to bid one more
time. He/she must either maintain the same amount or bid a higher amount. Notice that the customer
does NOT know the amount being bid by any customers. For this program, you can assume in this case
the customer will have a 50% chance of maintaining the same bid amount, and 50% chance of increasing
the bidding amount randomly. After that, the auctioneer will determine who get the highest bid, and
declare the winner. Notice that if there is a tie, no one win the auction and the item is discarded.
Once the round finishes, the auctioneer need to inform every table that the round is done, and inform
everyone who has won the auction (or nobody wins).
Input
Your program should read an input file. The input file have the following content:
The first line consists of six integers
o The first number is the number of tables available. It should be at least 2.
o The second number is the number of types of items (k in the description)
o The third number is the number of customers in the input file. It should be at least 2.
o The fourth number is the maximum numbers of items that are auctioned. If all the
items are auctioned, the main process should tell all customers that it is quitting (and
ask everyone to leave). On the other hand, if there is no customer left, the customer
should quit).
o The fifth number denote whether the items to be auctioned is to be generated
randomly. If it is 1, then the items are generated in a cyclic sequence of 1, 2, 3, …, k, 1,
2, 3 ….. Any other number denotes that the items is to be generated randomly.
o The sixth number is 1 if you want to run the extra credit, otherwise it is ignored.
Each subsequent line represents a customer. Each line has the following format:
o The first number is the ID of the customer (integer)
o The second number is the amount of money the customer has in the beginning (positive
integer)
o The third number denote the number of items that the customer is interested
o The rest of the line denote the type of each item that the customer is interested in (can
have duplicates)
You can assume the input file to follow the format. If the file input format is incorrect and your program
crash, you are not responsible.
Program Structure
Your program should have the following structure:
Main Process
Read the input file
Pre-process and initialization
Create the tables (threads)
Sit the initial customers
Repeat
Determine who can participate in the next round of auction
Select an item to auction
Auction the item
Send message to threads to denote who win/lose
Until all auction ends or all customers left
Print final information
Tell all threads to quit
Join all threads
Exit the program
Foe each thread
Initialization
Repeat
If there is no customer
Find a customer to sit join this table
Repeat
Going through each round of auction
Until customer leaves
Until told by the main program to quit
Print final information
Quit
Output Requirements
Your program should print the following statements. The output is considered a major part of this
project, so please follow direction closely.
When a customer is added to the customer queue, you should print the following statement
“Customer
added to the queue”
When a customer is assigned to a table, you should print “Customer
assigned to table
”.
When a customer leaves, you should print “Customer
leaves, winning
number of auction won> auctions, amount of money spent =
,
amount of money left =
For each round of auction:
o After determining who is eligible for this round, the program should print “the following
customers are eligible for this round of auction :
”
o After the item is selected, the program should print “Item of type
up for
auction”
o When anyone makes a bid (at any round), the program should print “Customer
the customer> at table
bids
”.
o When a second round of bidding is required, the program should output “Second round
of bidding needed”
o At the end of each auction, the program should print “Customer
won the auction,
with amount
”. IF no one win the auction, it should print “No one won the
auction”
o At the end of the program, you should print: “total number of item auctioned : <# of
auctioned> item, total number of item successfully auctioned: <# of item that have
actually been won by someone>, total amount:
items>”
Bonus (20 points, Required for 7343 students, optional for 5343 students)
Your program should create an extra thread that add new (randomly generated) customer. Your extra
thread structure should be like that
Repeat
Int Delay = 100000;
Int Dtry = 1;
Int x;
For (int I = 0; I < Dtry; i++)
For (int j = 0; j < Delay; j++)
X = 1;
Generate a random number between 0 and 4
If (number generated == 4)
Generate a random customer and add it to the queue
Dtry = Dtry + 1
Else
If (Dtry >: 2) then Dtry = Dtry / 2; else Dtry = 1
until received a message from the main process to quit
quit
Comment bonus
You will get a maximum of 5% bonus for comments in your program. To get that 5% you need to:
For each function, put comment to describe each parameter, and what is the expected output
For each mutex/semaphore used, denote what is it used for
For each critical section, denote when is the start and end of that critical section (you can name
your critical section in various ways to distinguish among them (if necessary))
For loops and conditional statements that do non-trivial work (you decide what is non-trivial)
put comment before it describing what it does.
What to hand in
You should put all you source code into a zip file and upload the zip file to Canvas
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做ceng0013 design of a pro...
2024-11-13
代做mech4880 refrigeration a...
2024-11-13
代做mcd1350: media studies a...
2024-11-13
代写fint b338f (autumn 2024)...
2024-11-13
代做engd3000 design of tunab...
2024-11-13
代做n1611 financial economet...
2024-11-13
代做econ 2331: economic and ...
2024-11-13
代做cs770/870 assignment 8代...
2024-11-13
代写amath 481/581 autumn qua...
2024-11-13
代做ccc8013 the process of s...
2024-11-13
代写csit040 – modern comput...
2024-11-13
代写econ 2070: introduc2on t...
2024-11-13
代写cct260, project 2 person...
2024-11-13
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!