Сравнить коммиты

...

9 Коммитов

3 изменённых файлов: 7215 добавлений и 77 удалений

7106
doctest.h Обычный файл

Разница между файлами не показана из-за своего большого размера Загрузить разницу

56
lab01.cbp Обычный файл
Просмотреть файл

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="lab01" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/lab01" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename=".gitignore" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="histogram_internal.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="text.cpp" />
<Unit filename="text.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

130
main.cpp
Просмотреть файл

@@ -1,92 +1,68 @@
#include <iostream>
#include <vector>
#include <curl/curl.h>
#include "histogram.h"
#include "text.h"
#include "svg.h"
using namespace std;
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
int main()
{
struct Input {
vector<double> numbers;
size_t bin_count{};
};
Input
input_data(istream& in, bool prompt) {
size_t number_count;
cerr << "Enter number count: ";
cin >> number_count;
vector<double> numbers(number_count);
cerr << "Enter numbers: ";
for(size_t i = 0; i < number_count; i++){
cin >> numbers[i];
}
size_t bin_count;
cerr << "Enter bin count: ";
cin >> bin_count;
double min = numbers[0];
double max = numbers[0];
/*
for (size_t x : numbers) {
if (x < min) {
min = x;
}
else if (x > max) {
max = x;
}
}
*/
for (size_t i=1; i<number_count; i++){
if (numbers[i]<min){
min=numbers[i];
}
else if (numbers[i]>max){
max=numbers[i];
}
}
vector<size_t> bins(bin_count);
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 ( (numbers[i] >= lo) && (numbers[i] < hi) ) {
bins[j]++;
found = true;
}
}
if (!found) {
bins[bin_count-1]++;
}
}
size_t max_count = bins[0];
for(size_t x: bins){
if(x > max_count){
max_count = x;
}
}
vector<size_t> heights(bin_count);
if (max_count>MAX_ASTERISK){
for (size_t i = 0; i < bin_count; i++){
heights[i] = MAX_ASTERISK * (static_cast<double>(bins[i]) /max_count);
if (prompt == true){
cerr << "input number count";
in >> number_count;
Input inn;
inn.numbers.resize(number_count);
cerr << "input numbers";
for (size_t i = 0; i < number_count; i++) {
cin >> inn.numbers[i];
}
cerr << "input bin count";
in >> inn.bin_count;
return inn;
}
else{
for (size_t i=0; i<bin_count; i++){
heights[i] = bins[i];
cout << "input number count";
in >> number_count;
Input inn;
inn.numbers.resize(number_count);
cout << "input numbers";
for (size_t i = 0; i < number_count; i++) {
cin >> inn.numbers[i];
}
cerr << "input bin count";
in >> inn.bin_count;
return inn;
}
for(size_t i=0; i<bin_count; i++){
if (bins[i] < 10){
cout << " " << bins[i] << "|";
}
int
main(int argc, char* argv[]){
CURL *curl = curl_easy_init();
if (argc>1){
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
res = curl_easy_perform(curl);
if (res!=CURLE_OK){
cerr<<curl_easy_strerror(res);
exit(1);
}
curl_easy_cleanup(curl);
}
else if (bins[i] < 100){
cout << " " << bins[i] << "|";
}
else{
cout << bins[i] << "|";
}
for (size_t j=0; j<heights[i]; j++){
cout<<"*";
}
cout<<"\n";
return 0;
}
curl_global_init(CURL_GLOBAL_ALL);
auto in = input_data(cin,true);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;
}