📄 bidhistory.cpp
字号:
#include "bidhistory.h"
#include "Advertisement.h"
void displayBidHistory(ostringstream &oss, Advertisement* ad) {
string email = ad->getEmail();
int quantity = ad->getQuantity();
Client *seller = users[email];
priority_queue<Bid> bids = ad->getBids();
int bidsNumber = bids.size();
//display the essential information
oss << "Posted by: <A HREF=mailto:>";
oss << seller->getLname() << ", " << seller->getFname() << "</a><br>" << endl;
oss << "Posted: " << ad->getStart() << "<br>" << endl;
oss << "Closes: " << ad->getClose() << "<br>" << endl;
oss << "Quantity: " << ad->getQuantity() << "<br>" << endl;
if(bidsNumber == 0){
oss<<"There are no bids on this advertisement.<br>\n";
return;
}
if(quantity == 1){//For advertisements that contain a quantity of one
oss<<bidsNumber<<" bid(s).<br>\n";
Bid current = bids.top();
oss<<"High bid is $"<<current.getAmount()<<" ("<<current.getEmail()<<")<br>\n";
return;
}
//For advertisements that contain a quantity of more than one
oss<<"Highest winning bid is $"<<bids.top().getAmount()<<"<br>\n";
for(int i = 0; i < bids.size() - 1; i++)
bids.pop();
oss<<"Lowest winning bid is $"<<bids.top().getAmount()<<"<br>\n<br>\n";
bids = ad->getBids();
oss<<"Highest bidders are: "<<"<br>\n<br>\n";
int total = 0;
for(i = 0; i < bidsNumber && total < quantity; i++){
Bid current = bids.top();
bids.pop();
int itemNumber = current.getQuantity();
total += itemNumber;
if(total > quantity)//can not buy excessively
itemNumber = itemNumber - (total - quantity);
if(bidsNumber != 1)
oss<<"<br>\t"<<i + 1<<". ";//the bidder's sequence
oss<<current.getEmail()<<" bid $"<<current.getAmount()<<" for each of "
<<current.getQuantity()<<" items and is the higher bidder for "
<<itemNumber<<" of them.<br>\n";
}
//the amount of items in the advertisement that have not been bid on.
int unbidNumber = (quantity - total) > 0 ? (quantity - total) : 0;
oss<<"<br>\n"<<unbidNumber<<" items remain unbid.<br>\n";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -