-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
63 lines (50 loc) · 2.38 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
53
54
55
56
57
58
59
60
61
62
63
#include <descriptive_statistics.hpp>
#include <tclap/CmdLine.h>
void process_cmd_line_args(int argc, char** argv);
int main(int argc, char** argv)
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
process_cmd_line_args(argc, argv);
std::string temporary_line{};
std::vector<double> data{};
data.reserve(1024);
while(std::cin>> temporary_line) {
data.emplace_back(std::atof(temporary_line.c_str()));
}
if(! std::is_sorted(data.cbegin(), data.cend()) ) {
std::sort(data.begin(), data.end());
}
std::cout<< DS(&*data.cbegin(), &*data.cend()) ;
return(EXIT_SUCCESS);
}
void process_cmd_line_args(int argc, char** argv) {
try {
TCLAP::CmdLine cmd("Descriptive Stats Tool", ' ', "0.1");
TCLAP::SwitchArg verbose_flag("v","verbose","Print value labels", cmd, false);
TCLAP::SwitchArg all_stats_flag("w","all","Print all stats", cmd, false);
TCLAP::SwitchArg min_flag("m","min","Print minimum value", cmd, false);
TCLAP::SwitchArg first_quartile_flag("f","first-quartile","Print first quartile", cmd, false);
TCLAP::SwitchArg mean_flag("a","mean","Print mean value", cmd, false);
TCLAP::SwitchArg median_flag("A","median","Print median value", cmd, false);
TCLAP::SwitchArg third_quartile_flag("t","third-quartile","Print third quartile", cmd, false);
TCLAP::SwitchArg max_flag("M","max","Print maximum value", cmd, false);
TCLAP::SwitchArg sum_flag("s","sum","Print sum of values", cmd, false);
TCLAP::SwitchArg variance_flag("V","variance","Print variance", cmd, false);
TCLAP::SwitchArg standard_deviation_flag("e","standard-deviation","Print standard deviation", cmd, false);
cmd.parse( argc, argv );
DS::VERBOSE = verbose_flag.getValue();
DS::ALL_STATS = all_stats_flag.getValue();
DS::MIN = min_flag.getValue();
DS::FIRST_QUARTILE = first_quartile_flag.getValue();
DS::MEAN = mean_flag.getValue();
DS::MEDIAN = median_flag.getValue();
DS::THIRD_QUARTILE = third_quartile_flag.getValue();
DS::MAX = max_flag.getValue();
DS::SUM = sum_flag.getValue();
DS::VARIANCE = variance_flag.getValue();
DS::STANDARD_DEVIATION = standard_deviation_flag.getValue();
} catch( TCLAP::ArgException &e ) {
std::cerr<< e.error() << std::endl;
}
}