-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
57 lines (51 loc) · 1.19 KB
/
main.cpp
File metadata and controls
57 lines (51 loc) · 1.19 KB
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
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
template<typename T>
void inputVector(vector<T>& vecT, int size)
{
for (int i = 0; i < size; ++i) {
T value;
cout << "Enter " << i+1 << " value:";
cin >> value;
vecT.push_back(value);
}
}
template<typename T>
T average(vector<T>& vecT)
{
T sum = accumulate(vecT.begin(),vecT.end(),T{});
return sum/(T)vecT.size();
}
int main() {
int size;
string type;
cout << "---Average---" << endl;
cout << "Enter massive size :";
cin >> size;
cout << "Enter massive type(int, double or float):";
cin >> type;
if(type == "int")
{
vector<int> myV;
inputVector(myV, size);
cout << "Average = " << average(myV) << endl;
}
else if (type == "double")
{
vector<double> myV;
inputVector(myV, size);
cout << "Average = " << average(myV) << endl;
}
else if (type == "float")
{
vector<float> myV;
inputVector(myV, size);
cout << "Average = " << average(myV) << endl;
}
else
cout << "Unknown type!" << endl;
cout << "---Bye, bye!---" << endl;
return 0;
}