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

..

3 Коммитов

Автор SHA1 Сообщение Дата
d3a3946351 code: конечный код 2024-05-18 16:20:49 +03:00
0a55523893 code: тестирование 2024-04-22 21:19:36 +03:00
29b252961b code: структурирование программы 2024-04-19 21:26:06 +03:00
3 изменённых файлов: 7151 добавлений и 88 удалений

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

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

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

@@ -1,97 +1,47 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include "histogram.h"
#include "text.h"
#include "svg.h"
using namespace std; using namespace std;
struct Input {
vector<double> numbers;
size_t bin_count{};
size_t number_count{};
size_t max_count{};
};
Input
input_data() {
Input in;
cerr << "Enter number count: ";
cin >> in.number_count;
vector<double> numbers(in.number_count);
in.numbers.resize(in.number_count);
for (size_t i = 0; i < in.number_count; i++) {
cin >> in.numbers[i];
}
size_t bin_count;
cerr << "Enter bin count: ";
cin >> in.bin_count;
size_t max_count;
in.max_count = 0;
return in;
}
int main() int main()
{ {
const size_t SCREEN_WIDTH = 80; auto in = input_data();
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3-1; 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);
size_t number_count;
cerr<<"Enter number count: ";
cin>>number_count;
vector<double>numbers(number_count);
//×èñëà
cerr<<"Enter elements: ";
for (int i=0; i<number_count;i++){
cin>>numbers[i];
}
//Êîëè÷åñòâî êîðçèí
size_t bin_count;
cerr<<"Enter bins count: ";
cin>>bin_count;
vector<size_t>bins(bin_count);
//Îïðåäåëåíèå äèàïàçîíà ÷èñåë (max è min) â ìàññèâå
double min=numbers[0];
double max=numbers[0];
for (double x: numbers){
if (x<min){
min=x;
}
else if (x>max){
max=x;
}
}
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]++;
}
}
//Ìàêñèìàëüíîå êîë-âî çâåçäî÷åê
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;
}
}
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<<"*";
}
cout<<endl;
}
}
else{
for (int i=0; i<bin_count; i++){
printf("%3d|", bins[i]);
for (int j=0; j<bins[i]; j++){
cout<<"*";
}
cout<<endl;
}
}
return 0; return 0;
} }

Просмотреть файл

@@ -32,7 +32,14 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>