-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
85 lines (72 loc) · 1.82 KB
/
main.cpp
File metadata and controls
85 lines (72 loc) · 1.82 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <fstream>
#include "stdio.h"
#include "unistd.h"
#include "stats_count.h"
//#include "stats_min.h"
/*#include "stats_mean.h"
#include "stats_median.h"
#include "stats_max.h"
#include "stats_mode.h"
#include "stats_count.h"*/
using namespace std;
int main(int argc, char **argv) {
int opt;
double val;
ifstream file;
vector<double> data;
string number;
file.open("data.txt");
while(!file.eof()){
getline(file, number);
data.push_back(std::stod(number));
}
while((opt = getopt(argc, argv, "cr")) != -1)
{
switch(opt)
{
case 'c':
stats_count stats;
double count;
count = stats.compute_count(data);
std::cout << "There are " << count << " elements in the file";
break;
//case 'n':
//stats_max;
/*case 'r':
stats_min min_finder;
double val;
while(cin >> val) {
min_finder.add(val);
}
cout << "min: " << min_finder.result() << endl;
break;*/
//case 'e':
//stats_mode;
default:
std::cout << "Options are:\n C count how many elements are in the file";
}
}
// optind is for the extra arguments
// which are not parsed
//for(; optind < argc; optind++){
// printf(“extra arguments: %s\n”, argv[optind]);
//}
//stats_mean mean_finder;
//stats_median median_finder;
//stats_max max_finder;
//stats_mode mode_finder;
//stats_count count_finder;
return 0;
}
// our code will calculate:
// - min
// - max
// - mean
// - median
// - mode
// - standard deviation
// - variance
// - range
// - sum
// - count