-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData.cpp
More file actions
81 lines (65 loc) · 1.52 KB
/
Copy pathData.cpp
File metadata and controls
81 lines (65 loc) · 1.52 KB
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
73
74
75
76
77
78
79
80
81
#include "Data.h"
Data::Data(){}
Data::Data(u_int32 size): values(std::vector<double>(size,0)){}
Data::Data(double k,u_int32 size) :values(std::vector<double>(size,k)){}
bool Data::IsEmpty() const{
return values.empty();
}
u_int32 Data::Size() const{
return values.size();
}
double Data::Max() const{
double max = *values.begin();
for(auto it : values)
{
if(it > max)
max = it;
}
return max;
}
double Data::Min() const{
double min = *values.begin();
for(auto it : values)
{
if(it < min)
min = it;
}
return min;
}
void Data::Pop(u_int32 count){
for(;count > 0;--count){
if(!IsEmpty()){
values.pop_back();
}
else break;
}
}
void Data::Append(double k,u_int32 count){
for(;count > 0;--count)
values.push_back(k);
}
double & Data::operator[](u_int32 k) const{
if(k < Size()){
auto it = values.begin() + k;
return const_cast<double &>(*it);
}
else throw std::string("Out of bounds!");
}
double Data::obtainTotal() const{
double tot = 0;
for(auto it : values)
{
tot += it;
}
return tot;
}
void Data::modIndex(u_int32 index, double value){
if(index < Size()){
values[index] = value;
}
else throw std::string("Out of bounds!");
}
chartItem::chartItem(){}
chartItem::chartItem(const std::string & name, const Data & a) : Data(a),label(name){}
void chartItem::setLabel(std::string text){label = text;}
std::string chartItem::getLabel() const{return label;}