code: добавление каталога с проверками кода

master
IvanovDA 1 год назад
Родитель 8d7947bbc6
Сommit ee8f95e22e

@ -0,0 +1,34 @@
#include <iostream>
#include <vector>
#include "histogram.h"
#include "text.h"
#include "histogram_internal.h"
using namespace std;
struct Input {
vector<double> numbers;
size_t bin_count{};
};
Input
input_data() {
Input in;
size_t number_count;
cin >> number_count;
in.numbers.resize(number_count);
for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i];
}
size_t bin_count;
cin >> in.bin_count;
return in;
}
int main() {
Input in = input_data();
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_text(bins);
return 0;
}

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

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

@ -0,0 +1,47 @@
#include <iostream>
#include <vector>
#include "histogram.h"
using namespace std;
void
find_minmax(const vector<double>& numbers, double& min, double& max) {
min = numbers[0];
for (size_t i = 1; i < numbers.size(); i++) {
if (numbers[i] < min) {
min = numbers[i];
}
else if (numbers[i] > max) {
max = numbers[i];
}
}
}
vector<size_t>
make_histogram(const vector <double>& numbers, size_t bin_count) {
double minc, maxc;
find_minmax(numbers, minc, maxc);
vector<size_t> bins(bin_count);
double bin_size = (maxc - minc) / bin_count;
size_t bin_max_size = 0;
for (size_t i = 0; i < numbers.size(); i++) {
bool found = false;
for (size_t j = 0; (j < bin_count - 1) && !found; j++) {
auto lo = minc + j * bin_size;
auto hi = minc + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
bins[j]++;
found = true;
if (bins[j] > bin_max_size) {
bin_max_size = bins[j];
}
}
}
if (!found) {
bins[bin_count - 1]++;
if (bins[bin_count - 1] > bin_max_size) {
bin_max_size = bins[bin_count - 1];
}
}
}
return bins;
}

@ -0,0 +1,6 @@
#pragma once
#include <vector>
std::vector<size_t>
make_histogram(const std::vector<double>& numbers, size_t bin_count);

@ -0,0 +1,6 @@
#pragma once
#include <vector>
void
find_minmax(const std::vector<double>& numbers, double& min, double& max);

@ -0,0 +1,35 @@
#include <iostream>
#include <vector>
#include "text.h"
using namespace std;
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
void
show_histogram_text(vector<size_t> bins) {
size_t bin_max_size = 0;
for (auto bin : bins) {
if (bin_max_size < bin) {
bin_max_size = bin;
}
}
double k = double(MAX_ASTERISK) / bin_max_size;
if (k > 1) {
k = 1;
}
for (size_t bin = 0; bin < bins.size(); bin++) {
if (bins[bin] < 100) {
cout << " ";
}
if (bins[bin] < 10) {
cout << " ";
}
cout << bins[bin] << "|";
for (size_t i = 0; i < bins[bin] * k; i++) {
cout << "*";
}
cout << endl;
}
}

@ -0,0 +1,5 @@
#pragma once
#include <vector>
void show_histogram_text(std::vector<size_t> bins);

@ -0,0 +1,12 @@
#define DOCTEST_CONFIG_NO_MULTITHREADING
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
TEST_CASE("distinct positive numbers") {
double min = 0;
double max = 0;
find_minmax({ 1, 2 }, min, max);
CHECK(min == 1);
CHECK(max == 2);
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\x64\Debug\cs-project3.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>

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

@ -0,0 +1,4 @@
 histogram.cpp
unittest.cpp
Создание кода...
cs-project3.vcxproj -> C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\x64\Debug\cs-project3.exe

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

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

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

@ -0,0 +1,2 @@
C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\cs-project3\histogram.cpp;C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\cs-project3\x64\Debug\histogram.obj
C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\cs-project3\unittest.cpp;C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\cs-project3\x64\Debug\unittest.obj

@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.39.33519:TargetPlatformVersion=10.0.22621.0:
Debug|x64|C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\|

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

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

@ -0,0 +1,2 @@
^C:\USERS\JUSTYGRASS\DESKTOP\PROGS\2_SEM\3LA\CS-PROJECT3\UNITTEST\CS-PROJECT3\X64\DEBUG\HISTOGRAM.OBJ|C:\USERS\JUSTYGRASS\DESKTOP\PROGS\2_SEM\3LA\CS-PROJECT3\UNITTEST\CS-PROJECT3\X64\DEBUG\UNITTEST.OBJ
C:\Users\justygrass\Desktop\progs\2_sem\3la\cs-project3\unittest\cs-project3\x64\Debug\cs-project3.ilk

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

Двоичные данные
unittest/cs-project3/x64/Debug/histogram.obj

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

Двоичные данные
unittest/cs-project3/x64/Debug/unittest.obj

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

Двоичные данные
unittest/cs-project3/x64/Debug/vc143.idb

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

Двоичные данные
unittest/cs-project3/x64/Debug/vc143.pdb

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

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34701.34
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cs-project3", "cs-project3\cs-project3.vcxproj", "{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}"
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
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Debug|x64.ActiveCfg = Debug|x64
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Debug|x64.Build.0 = Debug|x64
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Debug|x86.ActiveCfg = Debug|Win32
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Debug|x86.Build.0 = Debug|Win32
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Release|x64.ActiveCfg = Release|x64
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Release|x64.Build.0 = Release|x64
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Release|x86.ActiveCfg = Release|Win32
{BD27679B-0F5B-4A93-8719-6A6D1EB63DAD}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {81A4965D-810F-4368-ABFB-FA8AD08151B8}
EndGlobalSection
EndGlobal

Двоичные данные
unittest/x64/Debug/cs-project3.pdb

Двоичный файл не отображается.
Загрузка…
Отмена
Сохранить