Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

BidAnalysis.h

BiddingWarAnalysis.cpp | BiddingWarAnalysis.h | ShillBidAnalysis.h |


Читайте также:
  1. ShillBidAnalysis.h

SSD5 Exam

Calculating the average number of bits

 

BidAnalysis.cpp

 

/* Begin Student Code */

#include "BidAnalysis.h"

#include <numeric>

#include <functional>

#include <cassert>

#include <algorithm>

 

using namespace std;

 

BidAnalysis::BidAnalysis(Listing& listing, Categories& categories) {

convertRepresentation(listing, categories);

}

 

void BidAnalysis::convertRepresentation (Listing& listing, Categories& categories) {

 

const int SECONDS_IN_DAY = 24 * 60 * 60;

 

const int THREE_DAYS = SECONDS_IN_DAY * 3;

const int FIVE_DAYS = SECONDS_IN_DAY * 5;

const int SEVEN_DAYS = SECONDS_IN_DAY * 7;

 

Categories::iterator it;

for (it = categories.begin(); it!= categories.end(); it++) {

 

BidAverages averages;

 

int countAds3, countAds5, countAds7;

int countBids3, countBids5, countBids7;

countAds3 = countAds5 = countAds7 = 0;

countBids3 = countBids5 = countBids7 = 0;

 

vector<int>::iterator items;

for (items = (*it)->itemsBegin(); items!= (*it)->itemsEnd(); items++) {

 

Advertisement* ad = listing[*items];

double diff = ad->getClose() - ad->getStart();

 

int index = 0;

if (diff == THREE_DAYS) {

countAds3++;

countBids3 += ad->getBids().size();

} else if (diff == FIVE_DAYS) {

countAds5++;

countBids5 += ad->getBids().size();

} else if (diff == SEVEN_DAYS) {

countAds7++;

countBids7 += ad->getBids().size();

}

}

averages.category = (*it)->getName();

if (countAds3!= 0) averages.three = countBids3 / countAds3;

if (countAds5!= 0) averages.five = countBids5 / countAds5;

if (countAds7!= 0) averages.seven = countBids7 / countAds7;

averages.total = countAds3 + countAds5 + countAds7;

 

bids.push_back(averages);

 

}

}

 

bool compareTotals(const BidAverages& b1, const BidAverages& b2) {

 

if (b1.total > b2.total) {

return true;

}

else {

return false;

}

}

 

void BidAnalysis::showBidCountStatistics(void) {

 

sort(bids.begin(), bids.end(), compareTotals);

 

vector<BidAverages>::iterator it;

for (it = bids.begin(); it!= bids.end(); it++) {

 

cout << it->category << ": "

<< it->three << "\t"

<< it->five << "\t"

<< it->seven << "\t"

<< it->total << endl;

}

}

/* End Student Code */

 

BidAnalysis.h

/* Begin Student Code */

#ifndef BID_ANALYSIS_H

#define BID_ANALYSIS_H

 

#include <iostream>

#include <vector>

 

#include "Advertisement.h"

#include "Listing.h"

#include "Categories.h"

 

using namespace std;

 

struct BidAverages {

BidAverages(): category(""), three(0),

five(0), seven(0),

total(0) {}

 

string category;

double three;

double five;

double seven;

int total;

};

 

class BidAnalysis {

 

private:

vector<BidAverages> bids;

void convertRepresentation(Listing& listing, Categories& categories);

 

public:

BidAnalysis(Listing& listing, Categories& categories);

void showBidCountStatistics(void);

};

 

#endif

/* End Student Code */

 


Дата добавления: 2015-11-14; просмотров: 49 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
Форма декларации-заявки на проведение сертификации системы качества| Identifying Bid Snipers

mybiblioteka.su - 2015-2024 год. (0.006 сек.)