-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
52 lines (48 loc) · 1.68 KB
/
main.cpp
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
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
#include <float.h>
using namespace std;
int main(int argc, char *argv[]) {
if (argc < 2) {
cout << "Need 3 arguments at least" << endl;
return -1;
}
ifstream t(argv[1]);
if(t.is_open()) {
string s;
int col = atoi(argv[3]);
string sep = argv[2];
double small = DBL_MAX;
double big = DBL_MIN;
double sum = 0;
double numofterms = 0;
while(getline(t,s)) {
int pos = -1;
for (int i = 0; i < col; i++) {
pos = s.find(sep, pos + 1 );
}
int pos2 = pos+1;
pos2 = s.find(sep,pos2);
string t = s.substr(pos+1, pos2-pos-1);
stringstream ts(t);
double val;
if(ts >> val) {
cout << val << endl;
sum += val;
numofterms += 1;
if (val < small) {
small = val;
}
if (val > big) {
big = val;
}
}
}
double mean = sum/numofterms;
cout << "Biggest number is: " << big << endl;
cout << "Smallest number is: " << small << endl;
cout << "Mean is: " << mean << endl;
}
}