Сравнить коммиты
2 Коммитов
2eaf794295
...
1b1311833a
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 1b1311833a | |||
| 5135699b21 |
@@ -27,7 +27,7 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|||||||
return flag;
|
return flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<size_t> make_histogram(const vector<double> numbers, size_t bin_count, bool& flag){
|
vector<size_t> make_histogram(const vector<double> numbers, size_t bin_count){
|
||||||
vector<size_t> bins(bin_count);
|
vector<size_t> bins(bin_count);
|
||||||
double max, min = 0;
|
double max, min = 0;
|
||||||
find_minmax(numbers, min, max);
|
find_minmax(numbers, min, max);
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<size_t>
|
std::vector<size_t>
|
||||||
make_histogram(const std::vector<double> numbers, size_t bin_count, bool& flag);
|
make_histogram(const std::vector<double> numbers, size_t bin_count);
|
||||||
|
|
||||||
#endif // HISTOGRAM_H_INCLUDED
|
#endif // HISTOGRAM_H_INCLUDED
|
||||||
|
|||||||
74
main.cpp
74
main.cpp
@@ -6,6 +6,8 @@
|
|||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <svg.h>
|
#include <svg.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -21,9 +23,9 @@ struct Input {
|
|||||||
|
|
||||||
Input
|
Input
|
||||||
input_data(istream& in, bool prompt) {
|
input_data(istream& in, bool prompt) {
|
||||||
if (prompt == true) {
|
if (prompt == true){
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cerr << "amount of numbers";
|
cerr << "input number count";
|
||||||
in >> number_count;
|
in >> number_count;
|
||||||
Input inn;
|
Input inn;
|
||||||
inn.numbers.resize(number_count);
|
inn.numbers.resize(number_count);
|
||||||
@@ -34,14 +36,13 @@ input_data(istream& in, bool prompt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t bin_count;
|
size_t bin_count;
|
||||||
cerr << "amount of baskets";
|
cerr << "input amount of bins";
|
||||||
in >> inn.bin_count;
|
in >> inn.bin_count;
|
||||||
return inn;
|
return inn;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
else if (prompt == false) {
|
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cout << "amount of numbers";
|
cout << "input number count";
|
||||||
in >> number_count;
|
in >> number_count;
|
||||||
Input inn;
|
Input inn;
|
||||||
inn.numbers.resize(number_count);
|
inn.numbers.resize(number_count);
|
||||||
@@ -51,36 +52,59 @@ return inn;
|
|||||||
in >> inn.numbers[i];
|
in >> inn.numbers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bin_count;
|
size_t bin_count;
|
||||||
cout << "input baskets";
|
cout << "input amount of bins";
|
||||||
in >> inn.bin_count;
|
in >> inn.bin_count;
|
||||||
return inn;
|
return inn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static size_t
|
||||||
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
||||||
|
size_t data_size = item_size * item_count;
|
||||||
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||||
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input
|
||||||
|
download(const string& address) {
|
||||||
|
stringstream buffer;
|
||||||
|
CURL* curl = curl_easy_init();
|
||||||
|
if(curl)
|
||||||
|
{
|
||||||
|
CURLcode res;
|
||||||
|
const char* res2;
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
if (res!=0)
|
||||||
|
{
|
||||||
|
res2=curl_easy_strerror(res);
|
||||||
|
cout<<res2<<endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
return input_data(buffer, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Input in;
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
if(curl) {
|
if (argc > 1) {
|
||||||
CURLcode res;
|
in = download(argv[1]);
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, "http://uit.mpei.ru/study/courses/cs/lab03/marks.txt");
|
} else {
|
||||||
res = curl_easy_perform(curl);
|
in = input_data(cin, true);
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
|
auto procent = make_histogram_proc(in.numbers, in.bin_count, bins);
|
||||||
bool flag;
|
|
||||||
bool prompt;
|
|
||||||
prompt = true;
|
|
||||||
auto inn = input_data(cin, prompt);
|
|
||||||
auto bins = make_histogram(inn.numbers, inn.bin_count, flag);
|
|
||||||
auto procent = make_histogram_proc(inn.numbers, inn.bin_count, bins);
|
|
||||||
show_histogram_svg(bins, procent);
|
show_histogram_svg(bins, procent);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user