code: Выделена функция вычисления минимума и максимума
Этот коммит содержится в:
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -8,3 +8,4 @@
|
||||
/lab03.vcxproj.filters
|
||||
/lab03.vcxproj.user
|
||||
/.vs/
|
||||
/x64/
|
||||
@@ -18,6 +18,9 @@
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="lab1.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
@@ -126,9 +129,6 @@
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="lab03.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
||||
32
lab1.cpp
32
lab1.cpp
@@ -19,31 +19,35 @@ Input input_data() {
|
||||
return in;
|
||||
}
|
||||
|
||||
void find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||
min = numbers[0];
|
||||
max = numbers[0];
|
||||
for (double x : numbers)
|
||||
{
|
||||
if (x < min)
|
||||
{
|
||||
min = x;
|
||||
}
|
||||
if (x > max)
|
||||
{
|
||||
max = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
int i, j;
|
||||
double num;
|
||||
double min_number, max_number;
|
||||
Input in = input_data();
|
||||
find_minmax(in.numbers, min_number, max_number);
|
||||
vector<size_t> bins(in.bin_count);
|
||||
for (i = 0; i < in.bin_count; i++)
|
||||
{
|
||||
bins[i] = 0;
|
||||
}
|
||||
double min_number = in.numbers[0];
|
||||
double max_number = in.numbers[0];
|
||||
for (double x : in.numbers)
|
||||
{
|
||||
if (x < min_number)
|
||||
{
|
||||
min_number = x;
|
||||
}
|
||||
else if (x > max_number)
|
||||
{
|
||||
max_number = x;
|
||||
}
|
||||
}
|
||||
double bin_size = (max_number - min_number) / in.bin_count;
|
||||
for (size_t i = 0; i < in.numbers.size(); i++)
|
||||
{
|
||||
|
||||
Ссылка в новой задаче
Block a user