averagizer

v1
Brett 2023-02-16 00:03:01 -05:00
parent 7a181e0c71
commit 08524cd280
1 changed files with 32 additions and 0 deletions

View File

@ -560,6 +560,38 @@ namespace blt {
// << " {" << v.m30() << ", " << v.m31() << ", " << v.m32() << ", " << v.m33() << "} \n";
// }
template<typename T, int Size>
class averagizer_o_matic {
private:
T* data = new T[Size];
int index = 0;
public:
averagizer_o_matic(): averagizer_o_matic(0) {}
explicit averagizer_o_matic(T default_value){
for (int i = 0; i < Size; i++){
data[i] = default_value;
}
}
void insert(T t){
data[index++] = t;
if (index >= Size)
index = 0;
}
T average(){
T total = 0;
for (int i = 0; i < Size; i++){
total += data[i];
}
return total / Size;
}
~averagizer_o_matic(){
delete[] data;
}
};
}
#endif //BLT_MATH_H