code: заготовка программы
Этот коммит содержится в:
31
lab01.sln
Обычный файл
31
lab01.sln
Обычный файл
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34024.191
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab01", "lab01\lab01.vcxproj", "{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x64.Build.0 = Debug|x64
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Debug|x86.Build.0 = Debug|Win32
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x64.ActiveCfg = Release|x64
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x64.Build.0 = Release|x64
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x86.ActiveCfg = Release|Win32
|
||||
{EBF957AB-9D20-46E3-9D0A-D7A883E0071C}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {CE3404EF-11FE-4EC1-B337-9F770D1EEA0A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
65
lab01/lab01.cpp
Обычный файл
65
lab01/lab01.cpp
Обычный файл
@@ -0,0 +1,65 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
int i,j;
|
||||
string a,b,c;
|
||||
size_t number_count, bin_count;
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
cerr << "Enter colichestvo corzin: ";
|
||||
cin >> bin_count;
|
||||
vector <size_t> bins(bin_count);
|
||||
vector <double> numbers(number_count);
|
||||
for (i = 0; i < number_count; i++) {
|
||||
cin >> numbers[i];
|
||||
}
|
||||
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++) {
|
||||
double lo = min + j * bin_size;
|
||||
double hi = min + (j + 1) * bin_size;
|
||||
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
|
||||
bins[j]++;
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
bins[bin_count - 1]++;
|
||||
}
|
||||
}
|
||||
int maxlen = 0;
|
||||
for (int j = 0; j < bin_count; j++)
|
||||
{
|
||||
if (maxlen < bins[j]) maxlen = bins[j];
|
||||
}
|
||||
for (int j = 0; j < bin_count; j++)
|
||||
{
|
||||
if (bins[j] < 100) cout << " ";
|
||||
if (bins[j] < 10) cout << " ";
|
||||
cout << bins[j] << "|";
|
||||
size_t height = bins[j];
|
||||
if (maxlen > MAX_ASTERISK)
|
||||
{
|
||||
if (maxlen != bins[j]) height = MAX_ASTERISK * (static_cast<float>(bins[j]) / maxlen);
|
||||
else if (maxlen == bins[j]) height = MAX_ASTERISK;
|
||||
}
|
||||
for (int i = 0; i < height; i++) cout << "*";
|
||||
cout << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Ссылка в новой задаче
Block a user