Сравнить коммиты
7 Коммитов
9ec235110a
...
master
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 9222fab01d | |||
| 362b8bc328 | |||
| e034e80ec5 | |||
| 0f4226f2d1 | |||
| fa51bc942d | |||
| 593e1dae4a | |||
| 22bc72a0fc |
7106
doctest.h
Обычный файл
7106
doctest.h
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
16
lab01.cbp
16
lab01.cbp
@@ -32,7 +32,23 @@
|
|||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Unit filename=".gitignore" />
|
||||||
|
<Unit filename="histogram.cpp" />
|
||||||
|
<Unit filename="histogram.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="histogram_internal.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Unit filename="main.cpp" />
|
<Unit filename="main.cpp" />
|
||||||
|
<Unit filename="svg.cpp" />
|
||||||
|
<Unit filename="svg.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
|
<Unit filename="text.cpp" />
|
||||||
|
<Unit filename="text.h">
|
||||||
|
<Option target="<{~None~}>" />
|
||||||
|
</Unit>
|
||||||
<Extensions>
|
<Extensions>
|
||||||
<lib_finder disable_auto="1" />
|
<lib_finder disable_auto="1" />
|
||||||
</Extensions>
|
</Extensions>
|
||||||
|
|||||||
124
main.cpp
124
main.cpp
@@ -1,5 +1,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include "histogram.h"
|
||||||
|
#include "text.h"
|
||||||
|
#include "svg.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
const size_t SCREEN_WIDTH = 80;
|
const size_t SCREEN_WIDTH = 80;
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||||
@@ -10,95 +14,55 @@ struct Input {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data() {
|
input_data(istream& in, bool prompt) {
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cin >> number_count;
|
if (prompt == true){
|
||||||
Input in;
|
cerr << "input number count";
|
||||||
in.numbers.resize(number_count);
|
in >> number_count;
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
Input inn;
|
||||||
cin >> in.numbers[i];
|
inn.numbers.resize(number_count);
|
||||||
}
|
cerr << "input numbers";
|
||||||
cin >> in.bin_count;
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
return in;
|
cin >> inn.numbers[i];
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|
||||||
min = numbers[0];
|
|
||||||
max = numbers[0];
|
|
||||||
for (size_t x : numbers) {
|
|
||||||
if (x < min) {
|
|
||||||
min = x;
|
|
||||||
}
|
|
||||||
else if (x > max) {
|
|
||||||
max = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// (çäåñü êîä ïîèñêà ìèíèìóìà è ìàêñèìóìà)
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){
|
|
||||||
vector<size_t> bins(bin_count);
|
|
||||||
double min, max;
|
|
||||||
find_minmax(numbers, min, max);
|
|
||||||
double bin_size = (max-min)/bin_count;
|
|
||||||
for (size_t i = 0; i < numbers.size(); 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]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bins;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
show_histogram_text(vector<size_t> bins){
|
|
||||||
size_t max_count = bins[0];
|
|
||||||
for(size_t x: bins){
|
|
||||||
if(x > max_count){
|
|
||||||
max_count = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vector<size_t> heights(bins.size());
|
|
||||||
if (max_count>MAX_ASTERISK){
|
|
||||||
for (size_t i = 0; i < bins.size(); i++){
|
|
||||||
heights[i] = MAX_ASTERISK * (static_cast<double>(bins[i]) /max_count);
|
|
||||||
}
|
}
|
||||||
|
cerr << "input bin count";
|
||||||
|
in >> inn.bin_count;
|
||||||
|
return inn;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
for (size_t i=0; i<bins.size(); i++){
|
cout << "input number count";
|
||||||
heights[i] = bins[i];
|
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";
|
||||||
for(size_t i=0; i<bins.size(); i++){
|
in >> inn.bin_count;
|
||||||
if (bins[i] < 10){
|
return inn;
|
||||||
cout << " " << bins[i] << "|";
|
|
||||||
}
|
|
||||||
else if (bins[i] < 100){
|
|
||||||
cout << " " << bins[i] << "|";
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
cout << bins[i] << "|";
|
|
||||||
}
|
|
||||||
for (size_t j=0; j<heights[i]; j++){
|
|
||||||
cout<<"*";
|
|
||||||
}
|
|
||||||
cout<<"\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(){
|
main(int argc, char* argv[]){
|
||||||
auto in = input_data();
|
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);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
auto in = input_data(cin,true);
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
show_histogram_text(bins);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user