|
/* Begin Student Code */
#ifndef BIDDING_WAR_ANALYSIS_H
#define BIDDING_WAR_ANALYSIS_H
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include "Advertisement.h"
#include "Listing.h"
#include "Categories.h"
using namespace std;
struct CategoryStats {
CategoryStats(): numberWars(0), priceWars(0),
numberNonWars(0), priceNonWars(0),
percentDiff(0) {}
int numberWars;
double priceWars;
int numberNonWars;
double priceNonWars;
double percentDiff;
Category* cat;
};
bool operator<(const CategoryStats& cs1, const CategoryStats& cs2);
class BiddingWarAnalysis {
private:
static int NUMBER_OF_BIDDERS_IN_A_WAR;
static int MINIMUM_BIDS_IN_WAR;
map<Category*, CategoryStats> stats;
vector<CategoryStats> sorted;
void convertRepresentation(Listing& listing, Categories& categories);
bool isBiddingWar(Advertisement*);
void calculatePercentDiff(void);
public:
BiddingWarAnalysis(Listing& listing, Categories& categories);
void showBiddingWarStatistics(void);
};
#endif
/* End Student Code */
Identifying Shill Bidders
ShillBidAnalysis.cpp
/* Begin Student Code */
#pragma warning (disable: 4786)
#include "ShillBidAnalysis.h"
#include <numeric>
#include <functional>
using namespace std;
ShillBidAnalysis::ShillBidAnalysis(Listing& listing) {
convertRepresentation(listing);
}
void ShillBidAnalysis::convertRepresentation (Listing& listing) {
Listing::iterator it = listing.begin();
while (it!= listing.end()) {
Advertisement* ad = *it;
priority_queue<Bid> bids = ad->getBids();
vector<string> this_ad;
posters[ad->getEmail()].insert(ad);
// ignore bids placed by auction winner
string winner;
if (bids.size() > 0) {
winner = bids.top().getEmail();
bids.pop();
}
while (!bids.empty()) {
string bidder = bids.top().getEmail();
if (bidder!= winner) {
bidders[bidder].insert(ad);
}
bids.pop();
}
it++;
}
}
void ShillBidAnalysis::showShillBidders(void) {
map<string, set<Advertisement*> >::iterator bid_it;
map<string, set<Advertisement*> >::iterator post_it;
for (post_it = posters.begin(); post_it!= posters.end(); post_it++) {
if (post_it->second.size() > 1) {
cout << "\n" << post_it->first << " (" << post_it->second.size() << "): ";
for (bid_it = bidders.begin(); bid_it!= bidders.end(); bid_it++) {
if (includes(bid_it->second.begin(), bid_it->second.end(),
post_it->second.begin(), post_it->second.end())) {
cout << bid_it->first << " ";
}
}
}
}
}
/* End Student Code */
Дата добавления: 2015-11-14; просмотров: 80 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
BiddingWarAnalysis.cpp | | | ShillBidAnalysis.h |