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

...

2 Коммитов

Автор SHA1 Сообщение Дата
FilippovaYI 9ec235110a code: структурирование программы
12 месяцев назад
FilippovaYI bed2d1d21c build: lab01
12 месяцев назад

@ -0,0 +1,40 @@
<?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="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

@ -3,25 +3,29 @@
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;
int main()
{ struct Input {
vector<double> numbers;
size_t bin_count{};
};
Input
input_data() {
size_t number_count; size_t number_count;
cerr << "Enter number count: ";
cin >> number_count; cin >> number_count;
Input in;
vector<double> numbers(number_count); in.numbers.resize(number_count);
cerr << "Enter numbers: "; for (size_t i = 0; i < number_count; i++) {
for(size_t i = 0; i < number_count; i++){ cin >> in.numbers[i];
cin >> numbers[i];
} }
cin >> in.bin_count;
return in;
}
size_t bin_count; void
cerr << "Enter bin count: "; find_minmax(const vector<double>& numbers, double& min, double& max) {
cin >> bin_count; min = numbers[0];
max = numbers[0];
double min = numbers[0];
double max = numbers[0];
/*
for (size_t x : numbers) { for (size_t x : numbers) {
if (x < min) { if (x < min) {
min = x; min = x;
@ -30,18 +34,15 @@ int main()
max = x; max = x;
} }
} }
*/ // (çäåñü êîä ïîèñêà ìèíèìóìà è ìàêñèìóìà)
for (size_t i=1; i<number_count; i++){ }
if (numbers[i]<min){
min=numbers[i]; vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count){
}
else if (numbers[i]>max){
max=numbers[i];
}
}
vector<size_t> bins(bin_count); vector<size_t> bins(bin_count);
double min, max;
find_minmax(numbers, min, max);
double bin_size = (max-min)/bin_count; double bin_size = (max-min)/bin_count;
for (size_t i = 0; i < number_count; i++) { for (size_t i = 0; i < numbers.size(); i++) {
bool found = false; bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++) { for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
auto lo = min + j * bin_size; auto lo = min + j * bin_size;
@ -54,26 +55,30 @@ int main()
if (!found) { if (!found) {
bins[bin_count-1]++; bins[bin_count-1]++;
} }
} }
return bins;
}
void
show_histogram_text(vector<size_t> bins){
size_t max_count = bins[0]; size_t max_count = bins[0];
for(size_t x: bins){ for(size_t x: bins){
if(x > max_count){ if(x > max_count){
max_count = x; max_count = x;
} }
} }
vector<size_t> heights(bin_count); vector<size_t> heights(bins.size());
if (max_count>MAX_ASTERISK){ if (max_count>MAX_ASTERISK){
for (size_t i = 0; i < bin_count; i++){ for (size_t i = 0; i < bins.size(); i++){
heights[i] = MAX_ASTERISK * (static_cast<double>(bins[i]) /max_count); heights[i] = MAX_ASTERISK * (static_cast<double>(bins[i]) /max_count);
} }
} }
else{ else{
for (size_t i=0; i<bin_count; i++){ for (size_t i=0; i<bins.size(); i++){
heights[i] = bins[i]; heights[i] = bins[i];
} }
} }
for(size_t i=0; i<bin_count; i++){ for(size_t i=0; i<bins.size(); i++){
if (bins[i] < 10){ if (bins[i] < 10){
cout << " " << bins[i] << "|"; cout << " " << bins[i] << "|";
} }
@ -88,5 +93,12 @@ int main()
} }
cout<<"\n"; cout<<"\n";
} }
}
int
main(){
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins);
return 0; return 0;
} }

Загрузка…
Отмена
Сохранить