Ilya (OgarkovIA) 7 месяцев назад
Родитель 41a13d1ddf
Сommit 715b01fa7d

@ -0,0 +1,3 @@
9|******
33|*************************
100|****************************************************************************

@ -0,0 +1,3 @@
9|*********
33|*********************************
100|****************************************************************************************************

@ -0,0 +1,5 @@
142
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3

@ -0,0 +1,3 @@
9|******
33|*************************
100|****************************************************************************

@ -0,0 +1,3 @@
9|******
33|*************************
100|****************************************************************************

@ -0,0 +1,3 @@
9|******
33|*************************
100|****************************************************************************

@ -0,0 +1,5 @@
142
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3

@ -0,0 +1,10 @@
@echo off
lab01.exe < 01-example.input.txt > 01-example.actual.txt 2>NUL
fc /N 01-example.actual.txt 01-example.expected.txt
lab01.exe < 02-alignment.input.txt > 02-alignment.actual.txt 2>NUL
fc /N 02-alignment.actual.txt 02-alignment.expected.txt
lab01.exe < 03-scaling.input.txt > 03-alignment.actual.txt 2>NUL
fc /N 03-alignment.actual.txt 03-alignment.expected.txt

@ -0,0 +1,3 @@
@echo off
lab01.exe < 01-example.input.txt > 01-example.actual.txt 2>NUL
fc /N 01-example.actual.txt 01-example.expected.txt

@ -0,0 +1,3 @@
@echo off
lab01.exe < 02-alignment.input.txt > 02-alignment.actual.txt 2>NUL
fc /N 02-alignment.actual.txt 02-alignment.expected.txt

@ -0,0 +1,3 @@
@echo off
lab01.exe < 03-scaling.input.txt > 03-alignment.actual.txt 2>NUL
fc /N 03-alignment.actual.txt 03-alignment.expected.txt

@ -0,0 +1,77 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
size_t number_count, bin_count;
cerr << "Enter number count: ";
cin >> number_count;
vector<double> numbers(number_count);
cerr << "Enter the numbers:\n";
for (size_t i = 0; i < number_count; ++i) {
cerr << "Number " << i + 1 << ": ";
cin >> numbers[i];
}
cerr << "Enter bin count: ";
cin >> bin_count;
vector<size_t> bins(bin_count);
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]++;
}
}
size_t max_count = 0;
for (size_t i = 0; i < bin_count; ++i) {
if (bins[i] > max_count) {
max_count = bins[i];
}
}
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
for (size_t i = 0; i < bin_count; ++i) {
size_t height = 0;
if (max_count != 0) {
height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
}
cout << (bins[i] < 100 ? " " : "") << (bins[i] < 10 ? " " : "") << bins[i] << "|";
for (size_t j = 0; j < height; ++j) {
cout << "*";
}
cout << endl;
}
}

@ -0,0 +1,5 @@
142
1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
3

Двоичные данные
bin/Debug/lab01.exe

Двоичный файл не отображается.

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

@ -0,0 +1,8 @@
// histogram.cpp
#include "histogram.h"
#include "histogram_internal.h"
// Îïðåäåëåíèå ôóíêöèè make_histogram()
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count) {
// Ðåàëèçàöèÿ ôóíêöèè make_histogram()
}

@ -0,0 +1,11 @@
// histogram.h
#pragma once
#include <vector>
struct Input {
std::vector<double> numbers;
size_t bin_count;
};
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);

@ -0,0 +1,6 @@
#pragma once
#include <vector>
// Îáúÿâëåíèå ôóíêöèè find_minmax()
void find_minmax(const std::vector<double>& numbers, double& min, double& max);

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

@ -0,0 +1,7 @@
# depslib dependency file v1.0
1717401938 source:c:\users\Àëåêñàíäð\desktop\lab3\histogram.cpp
"histogram.h"
1717401531 c:\users\Àëåêñàíäð\desktop\lab3\histogram.h
<vector>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="text.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="text.h" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="170" topLine="0" />
</Cursor>
</File>
<File name="histogram.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="0" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="353" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>

@ -1,92 +1,35 @@
// main.cpp
#include <iostream>
#include <vector>
#include "histogram.h"
using namespace std;
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
int main()
{
Input input_data() {
size_t number_count;
cerr << "Enter number count: ";
cin >> number_count;
vector<double> numbers(number_count);
Input in;
in.numbers.resize(number_count);
cerr << "Enter numbers: ";
for(size_t i = 0; i < number_count; i++){
cin >> numbers[i];
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
}
size_t bin_count;
cerr << "Enter bin count: ";
cin >> bin_count;
cin >> in.bin_count;
double min = numbers[0];
double max = numbers[0];
for (double x : numbers) {
if (x < min) {
min = x;
}
else if (x > max) {
max = x;
}
}
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]++;
}
return in;
}
}
size_t max_count = bins[0];
for(size_t x: bins){
if(x > max_count){
max_count = x;
}
}
if (max_count > MAX_ASTERISK){
for(size_t count: bins){
size_t height = MAX_ASTERISK * (static_cast<double>(count) /max_count);
if (count < 10){
cout << " " << count << "|";
}
else if (count < 100){
cout << " " << count << "|";
}
else{
cout << count << "|";
}
for(size_t i = 0; i < height; i++){
cout << "*";
}
cout << "\n";
}
}
else{
for(double x : bins){
if (x < 10){
cout << " " << x << "|";
}
else if (x < 100){
cout << " " << x << "|";
}
else{
cout << x << "|";
}
for(size_t i = 0; i < x; i++){
cout << "*";
}
cout << "\n";
}
}
int main() {
auto in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins);
return 0;
}

Двоичные данные
main.exe

Двоичный файл не отображается.

Двоичные данные
main.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/Lab3/histogram.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/Lab3/unittest.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/histogram.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/main.o

Двоичный файл не отображается.

Двоичные данные
obj/Debug/text.o

Двоичный файл не отображается.

@ -0,0 +1,48 @@
// text.cpp
#include <iostream>
#include <vector>
#include "text.h"
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
// Îïðåäåëåíèå ôóíêöèè show_histogram_text()
void show_histogram_text(const std::vector<size_t>& bins) {
size_t max_count = bins[0];
for (size_t x : bins) {
if (x > max_count) {
max_count = x;
}
}
if (max_count > MAX_ASTERISK) {
for (size_t count : bins) {
size_t height = MAX_ASTERISK * (static_cast<double>(count) / max_count);
if (count < 10) {
std::cout << " " << count << "|";
} else if (count < 100) {
std::cout << " " << count << "|";
} else {
std::cout << count << "|";
}
for (size_t i = 0; i < height; i++) {
std::cout << "*";
}
std::cout << "\n";
}
} else {
for (size_t x : bins) {
if (x < 10) {
std::cout << " " << x << "|";
} else if (x < 100) {
std::cout << " " << x << "|";
} else {
std::cout << x << "|";
}
for (size_t i = 0; i < x; i++) {
std::cout << "*";
}
std::cout << "\n";
}
}
}

@ -0,0 +1,7 @@
// text.h
#pragma once
#include <vector>
// Îáúÿâëåíèå ôóíêöèè show_histogram_text()
void show_histogram_text(const std::vector<size_t>& bins);

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="unittest" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/unittest" 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/unittest" 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" />
</Compiler>
<Unit filename="../doctest.h.txt" />
<Unit filename="doctest.h.txt">
<Option compile="1" />
</Unit>
<Unit filename="histogram.cpp" />
<Unit filename="histogram_internal.h" />
<Unit filename="unittest.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>

@ -0,0 +1,13 @@
# depslib dependency file v1.0
1717403849 source:c:\users\Àëåêñàíäð\desktop\lab3\histogram.cpp
"histogram.h"
"histogram_internal.h"
1717402377 c:\users\Àëåêñàíäð\desktop\lab3\histogram.h
<vector>
1717403849 c:\users\Àëåêñàíäð\desktop\lab3\histogram_internal.h
<vector>
1717405577 source:c:\users\Àëåêñàíäð\desktop\lab3\unittest.cpp

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="unittest.cpp" open="0" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2" topLine="0" />
</Cursor>
</File>
<File name="histogram_internal.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="172" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Загрузка…
Отмена
Сохранить