-
Notifications
You must be signed in to change notification settings - Fork 1
/
ListStats.cpp
118 lines (89 loc) · 2.64 KB
/
ListStats.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "ListStats.hpp"
#include "List.hpp"
#include "math.h"
#include <iostream>
// TODO: implement this function - clear
unsigned long total_annual_wages(Employment *emp) {
auto l = list_length(emp);
auto c = emp;
unsigned long wages = 0;
for(int i = 0; i < l; i++){
wages += c->total_annual_wages;
c = c->next;
}
return wages;
}
// TODO: implement this function - clear
unsigned long min_annual_wages(Employment *emp) {
auto l = list_length(emp);
auto c = emp;
unsigned long wages = c->total_annual_wages;
for(int i = 0; i < l; i++){
if(c->total_annual_wages < wages){
wages = c->total_annual_wages;
}
c = c->next;
}
return wages;
}
// TODO: implement this function
unsigned long max_annual_wages(Employment *emp) {
auto l = list_length(emp);
auto c = emp;
unsigned long wages = c->total_annual_wages;
for(int i = 0; i < l; i++){
if(c->total_annual_wages > wages){
wages = c->total_annual_wages;
}
c = c->next;
}
return wages;
}
// TODO: implement this function
float stdev_annual_wages(Employment *emp) {
const int count = list_length(emp);
const double mean = static_cast<double>(total_annual_wages(emp))/count;
auto current = emp;
double internalSum = 0.0;
for(int i = 0; i < count; i++){
internalSum += pow(current->total_annual_wages - mean, 2.0);
current = current->next;
}
return static_cast<float>(pow(internalSum / count, 0.5));
}
// Unique Count
unsigned int unique_wages(Employment *emp){
auto vec = generateHistogram(emp);
int uniqueCount = 0;
for(unsigned int i = 0; i < vec.size(); i++){
if(vec[i][1] == 1){
uniqueCount++;
}
}
return uniqueCount;
}
// Distinct Wages
unsigned int distinct_wages(Employment *emp){
return generateHistogram(emp).size();
}
std::vector< std::vector<unsigned long> > generateHistogram(Employment *emp){
std::vector<std::vector<unsigned long>> vec = {};
auto count = list_length(emp);
auto current = emp;
for(int i = 0; i < count; i++){
auto currentWage = current->total_annual_wages;
bool found = false;
for(unsigned int j = 0; j < vec.size(); j++){
if(vec[j][0] == currentWage){
found = true;
vec[j][1]++;
}
}
if(!found){
std::vector<unsigned long> newNumber = {currentWage, 1};
vec.push_back(newNumber);
}
current = current->next;
}
return vec;
}