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

...

4 Коммитов

Автор SHA1 Сообщение Дата
63de96b3fe добавил argc argv 2023-06-09 22:17:28 +03:00
94f67b705c изменил ввод 2023-06-08 22:01:37 +03:00
ddd75f3b11 изменил ввод 2023-06-08 22:01:14 +03:00
17cda0871e библиотека для модульных тестов 2023-06-05 00:10:56 +03:00
3 изменённых файлов: 7215 добавлений и 89 удалений

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

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

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

@@ -32,7 +32,22 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<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="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> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

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

@@ -1,102 +1,50 @@
#include <iostream> #include "histogram.h"
#include <vector> #include "svg.h"
using namespace std; using namespace std;
int main() struct Input {
{ vector<double> numbers;
size_t numbers, columns, count; size_t bin_count{};
float minn, maxx, diff, lo, hi; };
cerr << "Quantity of numbers = "; cin >> numbers; Input
vector<float> xs(numbers); input_data(istream& inn, bool prompt)
cerr << "Enter your numbers: ";
for (int i = 0; i < numbers; ++i)
{ {
cin >> xs[i]; size_t number_count;
if (prompt == true)
cerr << "number_count = ";
inn >> number_count;
Input in;
in.numbers.resize(number_count);
if (prompt == true)
cerr << "numbers:";
for (size_t i = 0; i < number_count; i++) {
inn >> in.numbers[i];
} }
cerr << "Columns = "; cin >> columns; cerr << "columns = ";
vector<size_t> a(columns); cin >> in.bin_count;
return in;
}
maxx = xs[0]; int
minn = xs[0]; main(int argc, char* argv[])
for (int i = 0; i < numbers; i++)
{ {
if (xs[i] > maxx) if (argc > 1)
maxx = xs[i];
else
{ {
if (xs[i] < minn) cerr << argc;
minn = xs[i]; for(int i = 0; i < argc; i++){
cerr << "argv[" << i << "] = " << argv[i];
} }
return 0;
} }
auto in = input_data(cin, true);
diff = (maxx - minn) / columns; auto bins = make_histogram(in.numbers, in.bin_count);
lo = minn;
size_t max_count = 0; show_histogram_svg(bins);
for (int i = 0; i < columns; ++i)
{
count = 0;
if (i != columns - 1)
{
hi = lo + diff;
}
else
{
hi = maxx;
}
for (int j = 0; j < numbers; j++)
{
if (i == 0)
{
if ((xs[j] >= lo) && (xs[j] <= hi))
count++;
}
else
{
if ((xs[j] > lo) && (xs[j] <= hi))
count++;
}
}
a[i] = count;
lo = hi;
if (max_count < a[i])
max_count = a[i];
}
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t height;
for (int i = 0; i < columns; i++)
{
if (a[i] == 0)
continue;
if (a[i] < 10)
cout << " ";
else
if (a[i] < 100)
cout << " ";
cout << a[i] << "|";
if (max_count > MAX_ASTERISK)
height = MAX_ASTERISK * (static_cast<double>(a[i]) / max_count);
else
height = a[i];
for (int j = 0; j < height; j++)
{
cout << "*";
}
cout << endl;
}
} }