Сравнить коммиты
11 Коммитов
c763489475
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| f00edf17a3 | |||
| 68f82d1a3b | |||
| 0af7355eed | |||
| 61541cc2e0 | |||
| 42a69cd1bb | |||
| 4936fd20bb | |||
| f9f6bfb835 | |||
| 4f40624f31 | |||
| d3a3946351 | |||
| 0a55523893 | |||
| 29b252961b |
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -1,3 +1,4 @@
|
||||
/bin
|
||||
/obj
|
||||
/test.layout
|
||||
/curl
|
||||
|
||||
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
149
main.cpp
149
main.cpp
@@ -1,97 +1,112 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <curl/curl.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
#include "svg.h"
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3-1;
|
||||
//Êîëè÷åñòâî ÷èñåë
|
||||
|
||||
size_t number_count;
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
size_t number_count{};
|
||||
size_t max_count{};
|
||||
};
|
||||
|
||||
Input
|
||||
input_data(istream& in, bool prompt) {
|
||||
if (prompt==true){
|
||||
Input input;
|
||||
cerr << "Enter number count: ";
|
||||
cin>>number_count;
|
||||
vector<double>numbers(number_count);
|
||||
in >> input.number_count;
|
||||
|
||||
//×èñëà
|
||||
cerr<<"Enter elements: ";
|
||||
for (int i=0; i<number_count;i++){
|
||||
cin>>numbers[i];
|
||||
vector<double> numbers(input.number_count);
|
||||
input.numbers.resize(input.number_count);
|
||||
for (size_t i = 0; i < input.number_count; i++) {
|
||||
in >> input.numbers[i];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Êîëè÷åñòâî êîðçèí
|
||||
size_t bin_count;
|
||||
cerr<<"Enter bins count: ";
|
||||
cin>>bin_count;
|
||||
vector<size_t>bins(bin_count);
|
||||
cerr << "Enter bin count: ";
|
||||
in >> input.bin_count;
|
||||
|
||||
//Îïðåäåëåíèå äèàïàçîíà ÷èñåë (max è min) â ìàññèâå
|
||||
double min=numbers[0];
|
||||
double max=numbers[0];
|
||||
for (double x: numbers){
|
||||
if (x<min){
|
||||
min=x;
|
||||
size_t max_count;
|
||||
input.max_count = 0;
|
||||
return input;
|
||||
}
|
||||
else if (x>max){
|
||||
max=x;
|
||||
|
||||
if (prompt==false){
|
||||
Input input;
|
||||
|
||||
in >> input.number_count;
|
||||
|
||||
vector<double> numbers(input.number_count);
|
||||
input.numbers.resize(input.number_count);
|
||||
for (size_t i = 0; i < input.number_count; i++) {
|
||||
in >> input.numbers[i];
|
||||
}
|
||||
|
||||
size_t bin_count;
|
||||
in >> input.bin_count;
|
||||
|
||||
size_t max_count;
|
||||
input.max_count = 0;
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double bin_size=(max-min)/bin_count;
|
||||
|
||||
for (size_t i=0; i<number_count; i++){ //Îïîçíîâàíèå è óâåëè÷. ñ÷åò÷èêà ïîñëåäíåé êîðçèíû
|
||||
bool found =false;
|
||||
for (size_t j=0; (j<bin_count-1)&&!found; j++){
|
||||
auto lo=min+j*bin_size;
|
||||
auto hi = min+(j+1)*bin_size;
|
||||
if ((lo<=numbers[i])&&(numbers[i]<hi)){
|
||||
bins[j]++;
|
||||
found=true;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
bins[bin_count-1]++;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//Ìàêñèìàëüíîå êîë-âî çâåçäî÷åê
|
||||
int max_simb=0;
|
||||
for (int i=0; i<bin_count;i++){
|
||||
int c=0;
|
||||
c=bins[i];
|
||||
if (max_simb<c){
|
||||
max_simb=c;
|
||||
}
|
||||
|
||||
Input
|
||||
download(const string& address) {
|
||||
stringstream buffer;
|
||||
CURL *curl = curl_easy_init();
|
||||
curl_version_info_data *curl_version_info(CURLversion protocols);
|
||||
if(curl) {
|
||||
CURLcode res;
|
||||
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);
|
||||
curl_easy_cleanup(curl);
|
||||
if (res!=0){
|
||||
cout<<res;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (max_simb > MAX_ASTERISK){
|
||||
vector<size_t> hights(bin_count);
|
||||
for (size_t i = 0; i < bin_count; i++){
|
||||
size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_simb);
|
||||
hights[i] = height;
|
||||
printf("%3d|", bins[i]);
|
||||
for (int j=0; j<(hights[i]); j++){
|
||||
cout<<"*";
|
||||
curl_version_info_data *ver = curl_version_info(CURLVERSION_NOW);
|
||||
cerr<<(curl_version_info(CURLVERSION_NOW));
|
||||
}
|
||||
cout<<endl;
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
Input in;
|
||||
if (argc > 1) {
|
||||
in = download(argv[1]);
|
||||
}
|
||||
else {
|
||||
for (int i=0; i<bin_count; i++){
|
||||
printf("%3d|", bins[i]);
|
||||
for (int j=0; j<bins[i]; j++){
|
||||
cout<<"*";
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
in = input_data(cin, true);
|
||||
}
|
||||
const auto bins = make_histogram(in.numbers, in.bin_count, in.number_count, in.max_count);
|
||||
vector<double> test;
|
||||
show_histogram_svg(bins, in.max_count, in.bin_count, test);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
7
test.cbp
7
test.cbp
@@ -32,7 +32,14 @@
|
||||
<Add option="-Wall" />
|
||||
<Add option="-fexceptions" />
|
||||
</Compiler>
|
||||
<Unit filename="histogram.cpp" />
|
||||
<Unit filename="histogram.h" />
|
||||
<Unit filename="histogram_internal.h" />
|
||||
<Unit filename="main.cpp" />
|
||||
<Unit filename="svg.cpp" />
|
||||
<Unit filename="svg.h" />
|
||||
<Unit filename="text.cpp" />
|
||||
<Unit filename="text.h" />
|
||||
<Extensions>
|
||||
<lib_finder disable_auto="1" />
|
||||
</Extensions>
|
||||
|
||||
Ссылка в новой задаче
Block a user