⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calcstatistic.cpp

📁 大学时用c++做的计算器
💻 CPP
字号:
#include "calcstatistic.h"

CalculatorStatistic::CalculatorStatistic()
{
}

void CalculatorStatistic::store(const ValueType &data)
{
     __data.push_back(data);
}

void CalculatorStatistic::clear()
{
     __data.clear();
}

ValueType CalculatorStatistic::num()
{
     int size = __data.size();
     return (static_cast<ValueType>(size));
}

ValueType CalculatorStatistic::sum()
{
     ValueType sum = 0;
     
     for (int i = 0; i < __data.size(); i++)
           sum += __data[i];
     return sum;
}

ValueType CalculatorStatistic::average()
{
     if (__data.size() == 0)
        return 0;
     else
        return (sum() / __data.size());
}

ValueType CalculatorStatistic::stdDiff()
{
     ValueType  diff = 0;
     
     if (__data.size() == 0 || __data.size() == 1)
        return 0;
     else {
          for (int i = 0; i < __data.size(); i++)
              diff += (__data[i] - average()) * (__data[i] - average());
          diff = sqrt(diff / (__data.size() - 1));
          return diff;
     }
}

ValueType CalculatorStatistic::min()
{
     ValueType res = __data[0];
     
     if (__data.size() == 0)
        return 0;
     else {
        for (int i = 1; i < __data.size(); i++) {
            if (__data[i] < res)
               res = __data[i];
        }
        return res;
     }
}

ValueType CalculatorStatistic::max()
{
     ValueType res = __data[0];
     
     if (__data.size() == 0)
        return 0;
     else {
         for (int i=1;i<__data.size();i++) {
             if (__data[i] > res)
                 res = __data[i];
         }
         return res;
     }
}

ValueType CalculatorStatistic::load(const int index)
{
    return __data[index];
}

void CalculatorStatistic::del(const int index)
{
    if (index < __data.size())
    {
        __data.erase(__data.begin()+ index);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -