-
Notifications
You must be signed in to change notification settings - Fork 0
/
BubbleSortData.cpp
72 lines (63 loc) · 1.7 KB
/
BubbleSortData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Lucy Tran
9 - 19 - 16
Function File : Bubble Sort Data Class
PA1 : Bubblesort
*Data that is to be printed to the csv file
*Includes optimal, worst, and avg case data
*Includes the number of inputs (size of array): n
*Member Functions:
*Non-member Functions: operator<<
*/
#include "BubbleSortData.h"
/*Constructors*/
BubbleSortData::BubbleSortData() {
_n = 0;
}
BubbleSortData::BubbleSortData(int &n, CaseTime &optimal, CaseTime &worst, CaseTime &average) {
_n = n;
_optimal = optimal;
_worst = worst;
_average = average;
}
/*Destructor*/
BubbleSortData::~BubbleSortData() {}
/*Getters*/
int BubbleSortData::getN() const {
return _n;
}
CaseTime & BubbleSortData::getOptimal() {
return _optimal;
}
CaseTime & BubbleSortData::getWorst() {
return _worst;
}
CaseTime & BubbleSortData::getAverage() {
return _average;
}
/*Setters*/
void BubbleSortData::setN(int & newN) {
_n = newN;
}
void BubbleSortData::setOptimal(CaseTime newOptimal) {
_optimal = newOptimal; //calls overloaded assignment operator
}
void BubbleSortData::setWorst(CaseTime newWorst) {
_worst = newWorst;
}
void BubbleSortData::setAverage(CaseTime newAverage) {
_average = newAverage;
}
/*Non-Member Functions*/
//*Equivalent to one line in the csv file
//When you output a BubbleSortData object, the data will be outputted this way.
//N Optimal Worst Average Avg(1) Avg(2) ... Avg(5)
//The last part are the 5 trials for the average case
ostream & operator<< (ostream &output, BubbleSortData & dataObj)
{
output << dataObj.getN() << ",";
output << dataObj.getOptimal().getAvg() << ",";
output << dataObj.getWorst().getAvg() << ",";
output << dataObj.getAverage() << endl; //Ultilizing the overloaded << function for CaseTime
return output;
}