SukhotinMD 3 недель назад
Сommit 70f6892eb5

4
.gitignore поставляемый

@ -0,0 +1,4 @@
ProgUit Lab1.vcxproj
ProgUit Lab1.vcxproj.filters
ProgUit Lab1.vcxproj.user
/ARM64

@ -0,0 +1,4 @@
ProgUit Lab1.vcxproj
ProgUit Lab1.vcxproj.filters
ProgUit Lab1.vcxproj.user
/ARM64

@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35818.85 d17.13
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProgUit Lab1", "ProgUit Lab1\ProgUit Lab1.vcxproj", "{41E87DE9-8DF4-41BE-B56C-36C601839EC4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Debug|ARM64.ActiveCfg = Debug|ARM64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Debug|ARM64.Build.0 = Debug|ARM64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Debug|x64.ActiveCfg = Debug|x64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Debug|x64.Build.0 = Debug|x64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Debug|x86.ActiveCfg = Debug|Win32
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Debug|x86.Build.0 = Debug|Win32
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Release|ARM64.ActiveCfg = Release|ARM64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Release|ARM64.Build.0 = Release|ARM64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Release|x64.ActiveCfg = Release|x64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Release|x64.Build.0 = Release|x64
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Release|x86.ActiveCfg = Release|Win32
{41E87DE9-8DF4-41BE-B56C-36C601839EC4}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A6689844-BF3B-4F55-B9DF-6EC92110215A}
EndGlobalSection
EndGlobal

@ -0,0 +1,118 @@
#include <iostream>
#include <vector>
using namespace std;
int main()
{
// Объявление переменных
size_t number_count;
vector <double> numbers;
size_t bin_count;
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t User_Diagram;
// Ввод переменных
cerr << "Enter number count: " << endl;
cin >> number_count;
numbers.resize(number_count);
cerr << "Enter numbers: " << endl;
for (int i = 0; i < number_count; i++) {
cin >> numbers[i];
}
cerr << "Enter bin count: " << endl;
cin >> bin_count;
// Объявление перменных промежуточных/вывода
vector <size_t> bins(bin_count);
double max_in_numbers = *(max_element(begin(numbers), end(numbers)));
double min_in_numbers = *(min_element(begin(numbers), end(numbers)));
double bin_size = (max_in_numbers - min_in_numbers) / bin_count;
int max_in_bins = 0;
// Код
for (size_t i = 0; i < number_count; i++) {
int to_bin = int((numbers[i]) - min_in_numbers) / bin_size;
if (to_bin >= bin_count) {
bins[to_bin - 1]++;
}
else {
bins[to_bin]++;
}
}
// Максимальное в коорзинах
for (int i = 0; i < bin_count; i++) {
if (bins[i] > max_in_bins) {
max_in_bins = bins[i];
}
}
if (max_in_bins > MAX_ASTERISK) {
for (int i = 0; i < bin_count; i++) {
if (bins[i] < 100) {
cout << " ";
}
if (bins[i] < 10) {
cout << " ";
}
size_t height = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_in_bins);
cout << bins[i] << "|";
for (int j = 0; j < height; j++) {
cout << "*";
}
cout << endl;
}
} else {
// Если максимальное число среди коорзин меньше или равно 76
for (int i = 0; i < bin_count; i++) {
if (bins[i] < 100) {
cout << " ";
}
if (bins[i] < 10) {
cout << " ";
}
cout << bins[i] << "|";
for (int j = 0; j < bins[i]; j++) {
cout << "*";
}
cout << endl;
}
}
return 0;
}
Загрузка…
Отмена
Сохранить