Online Auction Program
Steven Zeil
1 Overview
Sellers at some of the better-known online auctioning sites complain about buyers who win an auction but then fail to make payment. Sellers sometimes give the excuse that they were bidding simultaneously on many items, and won more auctions than they had anticipated.
You are developing an online auction service where buyers will deposit funds with you before an auction, and where winning bids will be accepted only if sufficient funds remain in the bidder’s account.
Write a program to implement the rules of this auction, tracking the bids during a single day and determining the winners of each item for sale.
An auction is won by the highest bid that:
-
arrives no later than the second the auction ends,
-
is greater than or equal to the reserve price for the item, and
-
comes from a bidder who has at least the bid amount remaining in the bidder’s account at the instant the auction ends.
2 Input
There will be three input files, describing the items available for bid, the registered bidders, and the bids made during the auction, respectively. These three files will be named in the command line when the program is run.
2.1 Items
This file describes the items up for auction. It contains
-
A single line containing the number of items, $n_{\mbox{items}}$
-
$n_{\mbox{items}}$ lines, one for each item, in the form:
reserve-price auction-end-time item-name
-
reserve-price is the minimum price the seller will accept for an item. It is a number and is specified to the penny (0.01).
-
auction-end-time is in 24 hour format of the form XX:YY:ZZ where XX is in hours from 00 to 23, YY is in minutes from 00 to 59, and ZZ is in seconds from 00 to 59.
-
item-name is a string that begins with the first non-blank character after the auction-end-time and continues to the end of the input line.
-
You are guaranteed:
-
No two items will have the same name.
-
No two items will have the same auction end time.
-
Reserve prices will not be negative.
2.2 Bidders
This file describes the bidders who have registered for the auction. It contains
-
A single line containing the number of bidders, $n_{\mbox{bidders}}$
-
$n_{\mbox{bidders}}$ lines, one for each bidder, in the form:
bidder-name account-balance
-
bidder-name is a login name for the bidders, and consists of a single word (no internal blanks).
-
account-balance is the amount deposited by the bidder. It is a number and is specified to the penny (0.01).
-
You are guaranteed:
-
No two bidders will have the same name.
-
Account balances will not be negative.
2.3 Bids
This file describes the bids received in the day’s auction. It contains
-
A single line containing the number of bids, $n_{\mbox{bids}}$
-
$n_{\mbox{bids}}$ lines, one for each bidder, in the form:
bidder-name amount-bid time-of-bid item-name
-
bidder-name is a login name for the bidders, and consists of a single word (no internal blanks).
-
amount-bid is the amount bid. It is a number and is specified to the penny (0.01).
-
time-of-bid is in 24 hour format of the form XX:YY:ZZ as described earlier.
-
item-name is a string that begins with the first non-blank character after the time-of-bid and continues to the end of the input line.
-
You are guaranteed:
-
No two bids will have the same time.
-
Bid amounts will not be negative.
3 Output
Output will be written to standard out (cout
) and will consist of a list of items (one per line) in order of their auction finish time. Each output line will have the form:
item-name won by bidder-name for winning bid amount
If there is not a winning bid for an item, for that item the output line will be:
item-name reserve not met
4 Example
4.1 Sample Input
Suppose that file items.dat contains:
2
5.00 05:06:27 Chinese Vase
25.00 15:30:11 Hummel Figurine
and that file bidders.dat contains:
2
jjones 37.37
ssmith 55.55
and that file bids.dat contains:
3
jjones 26.00 00:18:03 Hummel Figurine
jjones 60.00 04:03:01 Chinese Vase
ssmith 27.00 09:03:05 Chinese Vase
4.2 Sample Output
Then if the program is invoked like this
program-name items.dat bidders.dat bids.dat
the output should be
Chinese Vase reserve not met
Hummel Figurine won by jjones for 26.00