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
| UpdateData(TRUE); string stringdata = CT2A(m_input.GetBuffer()); char* strdata=(char*)stringdata.c_str(); char* token, * next_token = NULL; char seps[] = " "; long double sum=0,e=0,s=0; vector<long double> data;
token = strtok_s(strdata, seps, &next_token);
while (token != NULL) { if (token != NULL) { data.push_back(stold(token)); token = strtok_s(NULL, seps, &next_token); } }
for (size_t i = 0; i <= data.size(); i++) sum += data[i]; e = sum / data.size();
for (size_t i = 0; i <= data.size(); i++) { if (i != data.size() - 1) s += (data[i] - e) * (data[i] - e); } s = s / data.size();
string sum_ret = to_string(sum); string e_ret = to_string(e); string s_ret = to_string(s);
m_sum = sum_ret.c_str(); m_avg = e_ret.c_str(); m_var = s_ret.c_str();
UpdateData(FALSE);
|