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
|
#include <iostream>
#include <vector>
#include <cmath>
#include <iterator>
using namespace std;
int fillVector(vector<int>& arbNums, int input, int user_ints);
double meanFunc(vector<int>& arbNums, int input, int user_ints);
double stndDev(vector<int>&arbNums, int input, double avg, int user_ints);
int main()
{
int user_input;
int user_integers;
double avg;
vector<int> v;
cout << "How many integers do you want in the vector?" << endl;
cin >> user_input;
fillVector(v, user_input, user_integers);
avg = meanFunc(v, user_input, user_integers);
cout << "The average of the vector is: " << avg << endl;
cout << "The standard deviation of the vector is: " << stndDev(v, user_input, avg, user_integers);
}
int fillVector(vector<int>&arbNums, int input, int user_ints)
{
for (int i = 0; i < input; i++)
{
cout << "Enter integers: " << endl;
cin >> user_ints;
arbNums.push_back(user_ints);
}
return 0;
}
double meanFunc(vector<int>&arbNums, int input, int user_ints)
{
int i;
double sum = 0;
double avg= 0;
for (i = 0; i < input; i++)
{
sum += arbNums[i];
avg = (sum) / (input);
}
return avg;
}
double stndDev(vector<int>&arbNums, int input, double avg, int user_ints)
{
int i;
double sum2 = 0;
double dev = 0;
for (i = 0; i < input; i++)
{
sum2 += pow((arbNums[i] - avg),2);
}
dev = sqrt(sum2 / (input -1));
return dev;
}
|