写作CS 5/7343程序、 辅导program编程语言

” 写作CS 5/7343程序、 辅导program编程语言CS 5/7343 Spring 2021Programming Homework 2Due Date: 4/3 (Sat) 11:59 pm (No extensions). 5% bonus if you hand in by 3/31 (Wed) 11:59pmThe goal of the program is to provide experience on using synchronization tools (mutex) and gain someexperience on server/threadpool programming.Application AuctionsThis program will simulate auctions. The main process will be an auctioneer which will have differenttype of items (denoted by integers 1 to k) up for auction. There may be more than one item available forauction for each type.Customers and tablesThere are a set of tables in the Auction house. (Each table should have an id, similar for what you dowith the threads in program 1). Each table will sit one customer. Customers arriving will be put into await queue (there is no limit on the length of the queue). For any table without a customer, it will scanthe 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 thecustomer may be interested in more than one item for a certain type, so the list of integers canhave 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 leaveimmediately.Each table is represented by a thread that is created in the beginning of the program. Once each threadis created, it is NOT joined when a customer leaves. Rather, the thread will see if there is any customeravailable on the wait queue and sit one of them if available. The thread only quits when the mainprocess tells it to.Each round of auctionA 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 tablesthat 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 randomamount (not more than the amount of money he/she has). A customer will bid 0 if he/she has nointerest 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 moretime. He/she must either maintain the Same amount or bid a higher amount. Notice that the customerdoes NOT know the amount being bid by any customers. For this program, you can assume in this casethe customer will have a 50% chance of maintaining the same bid amount, and 50% chance of increasingthe bidding amount randomly. After that, the auctioneer will determine who get the highest bid, anddeclare 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 informeveryone who has won the auction (or nobody wins).InputYour program should read an input file. The input file have the following content: The first line consists of six integerso 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 theitems are auctioned, the main process should tell all customers that it is quitting (andask everyone to leave). On the other hand, if there is no customer left, the customershould quit).o The fifth number denote whether the items to be auctioned is to be generatedrandomly. 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 (positiveinteger)o The third number denote the number of items that the customer is interestedo The rest of the line denote the type of each item that the customer is interested in (canhave duplicates)You can assume the input file to follow the Format. If the file input format is incorrect and your programcrash, you are not responsible.Program StructureYour program should have the following structure:Main ProcessRead the input filePre-process and initializationCreate the tables (threads)Sit the initial customersRepeatDetermine who can participate in the next round of auctionSelect an item to auctionAuction the itemSend message to Threads to denote who win/loseUntil all auction ends or all customers leftPrint final informationTell all threads to quitJoin all threadsExit the programFoe each threadInitializationRepeatIf there is no customerFind a customer to sit join this tableRepeatGoing through each round of auctionUntil customer leavesUntil told by the main program to quitPrint final informationQuitOutput RequirementsYour program should print the following statements. The output is considered a major part of thisproject, so please follow direction closely. When a customer is added to the customer queue, you should print the following statementCustomer ID of the customer added to the queue When a Customer is assigned to a table, you should print Customer ID of the customerassigned to table table ID. When a customer leaves, you should print Customer ID of the customer leaves, winning thenumber of auction won auctions, amount of money spent = amount of money spent,amount of money left = amount of money left For each round of auction:o After determining who is eligible for this round, the program should print the followingcustomers are eligible for this round of auction : list of ID of customers eligibleo After the item is selected, the program should print Item of type item type up forauctiono When anyone makes a bid (at any round), the program should print Customer ID ofthe customer at table table ID bids amount being bid.o When a second round of bidding is required, the program should output Second roundof bidding neededo At the end of Each auction, the program should print Customer ID won the auction,with amount bid amount. IF no one win the auction, it should print No one won theauctiono At the end of the program, you should print: total number of item auctioned : # ofauctioned item, total number of item successfully auctioned: # of item that haveactually been won by someone, total amount: sum of the total amount paid for theitemsBonus (20 points, Required for 7343 students, optional for 5343 students)Your program should create an extra thread that add new (randomly generated) customer. Your extrathread structure should be like thatRepeatInt 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 4If (number generated == 4)Generate a random customer and add it to the queueDtry = Dtry + 1ElseIf (Dtry : 2) then Dtry = Dtry / 2; else Dtry = 1until received a message from the main process to quitquitComment bonusYou 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 nameyour 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 inYou should put all you source code into a zip file and upload the zip file to Canvas请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导