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

..

Ничего общего в коммитах. '99ac195630ebfccb4b5a0a8a422710e63b682df1' и '3293105eab8f49890c6918dbd754f128a1db1570' имеют совершенно разные истории.

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

@ -2,18 +2,6 @@
.AppleDouble .AppleDouble
.LSOverride .LSOverride
# Xcode проекты
lab01.xcodeproj/
*.xcworkspace/
xcuserdata/
# Файлы пользовательских настроек Xcode
*.xcodeproj/project.xcworkspace/xcuserdata/
*.xcodeproj/xcuserdata/
UserInterfaceState.xcuserstate
# Системные файлы
.DS_Store
# Xcode # Xcode
*.xcuserdata/ *.xcuserdata/
*.xcuserstate *.xcuserstate

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

@ -1,45 +0,0 @@
#include "histogram.h"
#include <vector>
using namespace std;
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;
}
else if (x > max) {
max = x;
}
}
}
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
vector<size_t> bins(bin_count, 0);
double min, max;
find_minmax(numbers, min, max);
double bin_size = (max - min) / bin_count;
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 = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
bins[j]++;
found = true;
}
}
if (!found) {
bins[bin_count - 1]++;
}
}
return bins;
}

@ -1,16 +0,0 @@
//
// histogram.h
// lab01
//
// Created by Светлана Рыбакова on 01.05.2025.
//
#ifndef histogram_h
#define histogram_h
#include <vector>
std::vector<size_t>
make_histogram(const std::vector<double>& numbers, size_t bin_count);
#endif /* histogram_h */

@ -1,9 +0,0 @@
// histogram_internal.h
#ifndef HISTOGRAM_INTERNAL_H
#define HISTOGRAM_INTERNAL_H
#include <vector>
void find_minmax(const std::vector<double>& numbers, double& min, double& max);
#endif // HISTOGRAM_INTERNAL_H

@ -7,12 +7,11 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
3595A9962DC3B5DF0027AF89 /* histogram.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3595A9952DC3B5DF0027AF89 /* histogram.cpp */; }; 356052752DC3A6B7003C360D /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 356052742DC3A6B7003C360D /* main.cpp */; };
3595A9992DC3B6080027AF89 /* unittest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3595A9982DC3B6080027AF89 /* unittest.cpp */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
3560529E2DC3B4B2003C360D /* CopyFiles */ = { 3560526F2DC3A6B7003C360D /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase; isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/; dstPath = /usr/share/man/man1/;
@ -24,15 +23,12 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
356052A02DC3B4B2003C360D /* unittest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = unittest; sourceTree = BUILT_PRODUCTS_DIR; }; 356052712DC3A6B7003C360D /* lab01 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = lab01; sourceTree = BUILT_PRODUCTS_DIR; };
3595A9952DC3B5DF0027AF89 /* histogram.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = histogram.cpp; sourceTree = "<group>"; }; 356052742DC3A6B7003C360D /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
3595A9972DC3B5EC0027AF89 /* histogram_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = histogram_internal.h; sourceTree = "<group>"; };
3595A9982DC3B6080027AF89 /* unittest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = unittest.cpp; sourceTree = "<group>"; };
3595A99A2DC3B6930027AF89 /* doctest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = doctest.h; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
3560529D2DC3B4B2003C360D /* Frameworks */ = { 3560526E2DC3A6B7003C360D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
@ -42,21 +38,18 @@
/* End PBXFrameworksBuildPhase section */ /* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */ /* Begin PBXGroup section */
356052972DC3B4B2003C360D = { 356052682DC3A6B7003C360D = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
3595A9982DC3B6080027AF89 /* unittest.cpp */, 356052742DC3A6B7003C360D /* main.cpp */,
3595A99A2DC3B6930027AF89 /* doctest.h */, 356052722DC3A6B7003C360D /* Products */,
3595A9972DC3B5EC0027AF89 /* histogram_internal.h */,
3595A9952DC3B5DF0027AF89 /* histogram.cpp */,
356052A12DC3B4B2003C360D /* Products */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };
356052A12DC3B4B2003C360D /* Products */ = { 356052722DC3A6B7003C360D /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
356052A02DC3B4B2003C360D /* unittest */, 356052712DC3A6B7003C360D /* lab01 */,
); );
name = Products; name = Products;
sourceTree = "<group>"; sourceTree = "<group>";
@ -64,38 +57,38 @@
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */
3560529F2DC3B4B2003C360D /* unittest */ = { 356052702DC3A6B7003C360D /* lab01 */ = {
isa = PBXNativeTarget; isa = PBXNativeTarget;
buildConfigurationList = 356052A72DC3B4B2003C360D /* Build configuration list for PBXNativeTarget "unittest" */; buildConfigurationList = 356052782DC3A6B7003C360D /* Build configuration list for PBXNativeTarget "lab01" */;
buildPhases = ( buildPhases = (
3560529C2DC3B4B2003C360D /* Sources */, 3560526D2DC3A6B7003C360D /* Sources */,
3560529D2DC3B4B2003C360D /* Frameworks */, 3560526E2DC3A6B7003C360D /* Frameworks */,
3560529E2DC3B4B2003C360D /* CopyFiles */, 3560526F2DC3A6B7003C360D /* CopyFiles */,
); );
buildRules = ( buildRules = (
); );
dependencies = ( dependencies = (
); );
name = unittest; name = lab01;
productName = unittest; productName = lab01;
productReference = 356052A02DC3B4B2003C360D /* unittest */; productReference = 356052712DC3A6B7003C360D /* lab01 */;
productType = "com.apple.product-type.tool"; productType = "com.apple.product-type.tool";
}; };
/* End PBXNativeTarget section */ /* End PBXNativeTarget section */
/* Begin PBXProject section */ /* Begin PBXProject section */
356052982DC3B4B2003C360D /* Project object */ = { 356052692DC3A6B7003C360D /* Project object */ = {
isa = PBXProject; isa = PBXProject;
attributes = { attributes = {
BuildIndependentTargetsInParallel = 1; BuildIndependentTargetsInParallel = 1;
LastUpgradeCheck = 1540; LastUpgradeCheck = 1540;
TargetAttributes = { TargetAttributes = {
3560529F2DC3B4B2003C360D = { 356052702DC3A6B7003C360D = {
CreatedOnToolsVersion = 15.4; CreatedOnToolsVersion = 15.4;
}; };
}; };
}; };
buildConfigurationList = 3560529B2DC3B4B2003C360D /* Build configuration list for PBXProject "unittest" */; buildConfigurationList = 3560526C2DC3A6B7003C360D /* Build configuration list for PBXProject "lab01" */;
compatibilityVersion = "Xcode 14.0"; compatibilityVersion = "Xcode 14.0";
developmentRegion = en; developmentRegion = en;
hasScannedForEncodings = 0; hasScannedForEncodings = 0;
@ -103,30 +96,29 @@
en, en,
Base, Base,
); );
mainGroup = 356052972DC3B4B2003C360D; mainGroup = 356052682DC3A6B7003C360D;
productRefGroup = 356052A12DC3B4B2003C360D /* Products */; productRefGroup = 356052722DC3A6B7003C360D /* Products */;
projectDirPath = ""; projectDirPath = "";
projectRoot = ""; projectRoot = "";
targets = ( targets = (
3560529F2DC3B4B2003C360D /* unittest */, 356052702DC3A6B7003C360D /* lab01 */,
); );
}; };
/* End PBXProject section */ /* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */
3560529C2DC3B4B2003C360D /* Sources */ = { 3560526D2DC3A6B7003C360D /* Sources */ = {
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
3595A9962DC3B5DF0027AF89 /* histogram.cpp in Sources */, 356052752DC3A6B7003C360D /* main.cpp in Sources */,
3595A9992DC3B6080027AF89 /* unittest.cpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXSourcesBuildPhase section */ /* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */ /* Begin XCBuildConfiguration section */
356052A52DC3B4B2003C360D /* Debug */ = { 356052762DC3A6B7003C360D /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
@ -187,7 +179,7 @@
}; };
name = Debug; name = Debug;
}; };
356052A62DC3B4B2003C360D /* Release */ = { 356052772DC3A6B7003C360D /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
@ -241,7 +233,7 @@
}; };
name = Release; name = Release;
}; };
356052A82DC3B4B2003C360D /* Debug */ = { 356052792DC3A6B7003C360D /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
@ -249,7 +241,7 @@
}; };
name = Debug; name = Debug;
}; };
356052A92DC3B4B2003C360D /* Release */ = { 3560527A2DC3A6B7003C360D /* Release */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
@ -260,25 +252,25 @@
/* End XCBuildConfiguration section */ /* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */ /* Begin XCConfigurationList section */
3560529B2DC3B4B2003C360D /* Build configuration list for PBXProject "unittest" */ = { 3560526C2DC3A6B7003C360D /* Build configuration list for PBXProject "lab01" */ = {
isa = XCConfigurationList; isa = XCConfigurationList;
buildConfigurations = ( buildConfigurations = (
356052A52DC3B4B2003C360D /* Debug */, 356052762DC3A6B7003C360D /* Debug */,
356052A62DC3B4B2003C360D /* Release */, 356052772DC3A6B7003C360D /* Release */,
); );
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
356052A72DC3B4B2003C360D /* Build configuration list for PBXNativeTarget "unittest" */ = { 356052782DC3A6B7003C360D /* Build configuration list for PBXNativeTarget "lab01" */ = {
isa = XCConfigurationList; isa = XCConfigurationList;
buildConfigurations = ( buildConfigurations = (
356052A82DC3B4B2003C360D /* Debug */, 356052792DC3A6B7003C360D /* Debug */,
356052A92DC3B4B2003C360D /* Release */, 3560527A2DC3A6B7003C360D /* Release */,
); );
defaultConfigurationIsVisible = 0; defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release; defaultConfigurationName = Release;
}; };
/* End XCConfigurationList section */ /* End XCConfigurationList section */
}; };
rootObject = 356052982DC3B4B2003C360D /* Project object */; rootObject = 356052692DC3A6B7003C360D /* Project object */;
} }

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

@ -1,38 +1,84 @@
#include <vector> #include <vector>
#include <iostream> #include <iostream>
#include "histogram.h"
#include "text.h"
#include "svg.h"
using namespace std;
struct Input { using namespace std;
vector<double> numbers;
size_t bin_count{};
};
Input input_data() { int main() {
Input in; const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
size_t number_count; size_t number_count;
cerr << "Enter number count: "; cerr << "Enter number count: ";
cin >> number_count; cin >> number_count;
in.numbers.resize(number_count); vector<double> numbers(number_count);
cerr << "Enter numbers: "; cerr << "Enter numbers: ";
for (size_t i = 0; i < number_count; i++) { for (size_t i = 0; i < number_count; i++) {
cin >> in.numbers[i]; cin >> numbers[i];
} }
size_t bin_count;
cerr << "Enter bin count: "; cerr << "Enter bin count: ";
cin >> in.bin_count; cin >> bin_count;
return in; vector<size_t> bins(bin_count, 0);
}
int main() { double min = numbers[0];
auto in = input_data(); double max = numbers[0];
auto bins = make_histogram(in.numbers, in.bin_count); for (double x : numbers) {
show_histogram_svg(bins); 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++) {
auto lo = min + j * bin_size;
auto hi = min + (j + 1) * bin_size;
if ((lo <= numbers[i]) && (numbers[i] < hi)) {
bins[j]++;
found = true;
}
}
if (!found) {
bins[bin_count - 1]++;
}
}
size_t max_bin_count = 0;
for (size_t bin : bins) {
if (bin > max_bin_count) {
max_bin_count = bin;
}
}
if (max_bin_count <= MAX_ASTERISK) {
for (size_t i = 0; i < bin_count; i++) {
if (bins[i] < 10) cout << " ";
cout << " " << bins[i] << "|";
for (size_t j = 0; j < bins[i]; j++) {
cout << "*";
}
cout << endl;
}
} else {
for (size_t i = 0; i < bin_count; i++) {
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / max_bin_count));
if (bins[i] < 100) cout << " ";
if (bins[i] < 10) cout << " ";
cout << bins[i] << "|";
for (size_t j = 0; j < height; j++) {
cout << "*";
}
cout << endl;
}
}
return 0; return 0;
} }

@ -1,3 +0,0 @@
<?xml version='1.0' encoding='UTF-8'?>
<svg width='400' height='300' viewBox='0 0 400 300' xmlns='http://www.w3.org/2000/svg'>
</svg>

До

Ширина:  |  Высота:  |  Размер: 134 B

@ -1,4 +0,0 @@
10
3 3 4 4 4 4 4 5 5 5
3

@ -1,58 +0,0 @@
#include "svg.h"
#include <iostream>
using namespace std;
void svg_begin(double width, double height) {
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
cout << "<svg ";
cout << "width='" << width << "' height='" << height << "' ";
cout << "viewBox='0 0 " << width << " " << height << "' ";
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
}
void svg_end() {
cout << "</svg>\n";
}
void svg_text(double left, double baseline, const string& text) {
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>\n";
}
void svg_rect(double x, double y, double width, double height,
const string& stroke, const string& fill) {
cout << "<rect x='" << x << "' y='" << y << "' width='" << width
<< "' height='" << height
<< "' stroke='" << stroke
<< "' fill='" << fill << "' />\n";
}
void show_histogram_svg(const vector<size_t>& bins) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20;
const auto TEXT_WIDTH = 50;
const auto BIN_HEIGHT = 30;
size_t max_count = 0;
for (size_t count : bins) {
if (count > max_count) {
max_count = count;
}
}
double BLOCK_WIDTH = (IMAGE_WIDTH - TEXT_WIDTH) / static_cast<double>(max_count);
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
double top = 0;
for (size_t bin : bins) {
double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "#aaaaff");
top += BIN_HEIGHT;
}
svg_end();
}

15
svg.h

@ -1,15 +0,0 @@
#ifndef SVG_H
#define SVG_H
#include <vector>
#include <string>
void svg_begin(double width, double height);
void svg_end();
void svg_text(double left, double baseline, const std::string& text);
void svg_rect(double x, double y, double width, double height,
const std::string& stroke = "black",
const std::string& fill = "black");
void show_histogram_svg(const std::vector<size_t>& bins);
#endif // SVG_H

@ -1,40 +0,0 @@
#include "text.h"
#include <iostream>
using namespace std;
void show_histogram_text(const vector<size_t>& bins) {
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 4;
size_t max_bin_count = 0;
for (size_t bin : bins) {
if (bin > max_bin_count) {
max_bin_count = bin;
}
}
if (max_bin_count <= MAX_ASTERISK) {
for (size_t bin : bins) {
if (bin < 10) cout << " ";
cout << " " << bin << "|";
for (size_t j = 0; j < bin; j++) {
cout << "*";
}
cout << endl;
}
} else {
for (size_t bin : bins) {
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bin) / max_bin_count));
if (bin < 100) cout << " ";
if (bin < 10) cout << " ";
cout << bin << "|";
for (size_t j = 0; j < height; j++) {
cout << "*";
}
cout << endl;
}
}
}

@ -1,8 +0,0 @@
#ifndef TEXT_H_INCLUDED
#define TEXT_H_INCLUDED
#include <vector>
void show_histogram_text(const std::vector<size_t>& bins);
#endif // TEXT_H_INCLUDED

@ -1,39 +0,0 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest.h"
#include "histogram_internal.h"
TEST_CASE("Test find_minmax with distinct positive numbers") {
double min, max;
find_minmax({1, 2}, min, max);
CHECK(min == 1);
CHECK(max == 2);
}
TEST_CASE("Test find_minmax with single element") {
double min, max;
find_minmax({5}, min, max);
CHECK(min == 5);
CHECK(max == 5);
}
TEST_CASE("Test find_minmax with negative numbers") {
double min, max;
find_minmax({-3, -1, -2}, min, max);
CHECK(min == -3);
CHECK(max == -1);
}
TEST_CASE("Test find_minmax with equal elements") {
double min, max;
find_minmax({7, 7, 7}, min, max);
CHECK(min == 7);
CHECK(max == 7);
}
TEST_CASE("Mixed positive and negative numbers") {
double min, max;
find_minmax({-5.0, 0.0, 5.0}, min, max);
CHECK(min == -5.0);
CHECK(max == 5.0);
}
Загрузка…
Отмена
Сохранить