build: разделение программы на файлы

main
ShchegolikhYR 2 месяцев назад
Родитель e001cd2c68
Сommit d21b2f37d6

Двоичные данные
.DS_Store поставляемый

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

@ -8,6 +8,9 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
523FBF7E2DA909BA0044A741 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 523FBF7D2DA909BA0044A741 /* main.cpp */; }; 523FBF7E2DA909BA0044A741 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 523FBF7D2DA909BA0044A741 /* main.cpp */; };
52D010C52DC397980091060B /* histogram.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52D010C42DC397980091060B /* histogram.cpp */; };
52D010C62DC39F250091060B /* histogram.hpp in Sources */ = {isa = PBXBuildFile; fileRef = 52D010C32DC397980091060B /* histogram.hpp */; };
52FD91E52DC3AA580037B82C /* text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52FD91E42DC3AA580037B82C /* text.cpp */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */ /* Begin PBXCopyFilesBuildPhase section */
@ -24,7 +27,11 @@
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
523FBF7D2DA909BA0044A741 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; }; 523FBF7D2DA909BA0044A741 /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
52D010C32DC397980091060B /* histogram.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = histogram.hpp; sourceTree = "<group>"; };
52D010C42DC397980091060B /* histogram.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = histogram.cpp; sourceTree = "<group>"; };
52E197562D5F35A1004F8E3E /* Gistogramma */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Gistogramma; sourceTree = BUILT_PRODUCTS_DIR; }; 52E197562D5F35A1004F8E3E /* Gistogramma */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Gistogramma; sourceTree = BUILT_PRODUCTS_DIR; };
52FD91E32DC3AA580037B82C /* text.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = text.hpp; sourceTree = "<group>"; };
52FD91E42DC3AA580037B82C /* text.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = text.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -41,6 +48,10 @@
52E1974D2D5F35A1004F8E3E = { 52E1974D2D5F35A1004F8E3E = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
52FD91E32DC3AA580037B82C /* text.hpp */,
52FD91E42DC3AA580037B82C /* text.cpp */,
52D010C32DC397980091060B /* histogram.hpp */,
52D010C42DC397980091060B /* histogram.cpp */,
523FBF7D2DA909BA0044A741 /* main.cpp */, 523FBF7D2DA909BA0044A741 /* main.cpp */,
52E197572D5F35A1004F8E3E /* Products */, 52E197572D5F35A1004F8E3E /* Products */,
); );
@ -115,6 +126,9 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
523FBF7E2DA909BA0044A741 /* main.cpp in Sources */, 523FBF7E2DA909BA0044A741 /* main.cpp in Sources */,
52D010C52DC397980091060B /* histogram.cpp in Sources */,
52FD91E52DC3AA580037B82C /* text.cpp in Sources */,
52D010C62DC39F250091060B /* histogram.hpp in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

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

@ -100,5 +100,21 @@
landmarkType = "9"> landmarkType = "9">
</BreakpointContent> </BreakpointContent>
</BreakpointProxy> </BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "D37AA5D9-CDCD-44A1-A376-CD34E37F87BE"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "main.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "86"
endingLineNumber = "86"
landmarkName = "main()"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints> </Breakpoints>
</Bucket> </Bucket>

@ -0,0 +1,31 @@
#include <vector>
#include "histogram.hpp"
using namespace std;
static void find_minmax(const vector<double>& numbers, double& minimum, double& maximum) {
minimum = numbers[0];
maximum = numbers[0];
for (auto i : numbers) {
if (i < minimum) minimum = i;
if (i > maximum) maximum = i;
}
}
vector<size_t> make_histogram(const vector<double>& numbers, size_t& bin_count) {
vector<size_t> baskets(bin_count);
double basket_max;
double basket_min;
double basket_size;
find_minmax(numbers, basket_min, basket_max);
basket_size = (basket_max - basket_min) / bin_count;
for (auto i = 0; i < bin_count; i++) {
for (auto j = 0; j < numbers.size(); j++) {
if ((numbers[j] >= (basket_min + i * basket_size) and numbers[j] < (basket_min + (i + 1) * basket_size)) or (i == bin_count - 1 and numbers[j] == basket_max)) {
baskets[i]++;
}
}
}
return baskets;
}

@ -0,0 +1,7 @@
#ifndef histogram_hpp
#define histogram_hpp
#include <vector>
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t& bin_count);
#endif /* histogram_hpp */

@ -1,6 +1,9 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <string> #include <string>
#include "histogram.hpp"
#include "text.hpp"
using namespace std; using namespace std;
struct Input { struct Input {
@ -26,57 +29,57 @@ Input input_data() {
return in; return in;
} }
void find_minmax(const vector<double>& numbers, double& minimum, double& maximum) { //void find_minmax(const vector<double>& numbers, double& minimum, double& maximum) {
minimum = numbers[0]; // minimum = numbers[0];
for (int i : numbers) { // for (int i : numbers) {
if (i < minimum) minimum = i; // if (i < minimum) minimum = i;
} // }
maximum = numbers[0]; // maximum = numbers[0];
for (int i : numbers) { // for (int i : numbers) {
if (i > maximum) maximum = i; // if (i > maximum) maximum = i;
} // }
} //}
vector<size_t> make_histogram(const vector<double>& numbers, size_t& bin_count) { //vector<size_t> make_histogram(const vector<double>& numbers, size_t& bin_count) {
vector <size_t> baskets; // vector <size_t> baskets;
baskets.resize(bin_count); // baskets.resize(bin_count);
//
double basket_max; // double basket_max;
double basket_min; // double basket_min;
double basket_size; // double basket_size;
//
find_minmax(numbers, basket_min, basket_max); // find_minmax(numbers, basket_min, basket_max);
basket_size = (basket_max - basket_min) / bin_count; // basket_size = (basket_max - basket_min) / bin_count;
for (int i = 0; i < bin_count; i++) { // for (int i = 0; i < bin_count; i++) {
for (int j = 0; j < numbers.size(); j++) { // for (int j = 0; j < numbers.size(); j++) {
if ((numbers[j] >= (basket_min + i * basket_size) and numbers[j] < (basket_min + (i + 1) * basket_size)) or (i == bin_count - 1 and numbers[j] == basket_max)) { // if ((numbers[j] >= (basket_min + i * basket_size) and numbers[j] < (basket_min + (i + 1) * basket_size)) or (i == bin_count - 1 and numbers[j] == basket_max)) {
baskets[i]++; // baskets[i]++;
} // }
} // }
} // }
return baskets; // return baskets;
} //}
void show_histogram_text(const vector<size_t>& baskets) { //void show_histogram_text(const vector<size_t>& baskets) {
const size_t screen_width = 80; // const size_t screen_width = 80;
const size_t max_asterisk = screen_width - 3 - 1; // const size_t max_asterisk = screen_width - 3 - 1;
cout.precision(4); // cout.precision(4);
size_t baskets_max_count; // size_t baskets_max_count;
//
baskets_max_count = baskets[0]; // baskets_max_count = baskets[0];
for (size_t i : baskets) { // for (size_t i : baskets) {
if (i > baskets_max_count) baskets_max_count = i; // if (i > baskets_max_count) baskets_max_count = i;
} // }
for (int i = 0; i < baskets.size(); i++) { // for (int i = 0; i < baskets.size(); i++) {
size_t height = baskets[i]; // size_t height = baskets[i];
if (baskets_max_count > max_asterisk) { // if (baskets_max_count > max_asterisk) {
height = max_asterisk * (static_cast<double>(baskets[i]) / baskets_max_count); // height = max_asterisk * (static_cast<double>(baskets[i]) / baskets_max_count);
} // }
cout << baskets[i] << "|"; // cout << baskets[i] << "|";
for (int j = 0; j < height; j++) cout << "*"; // for (int j = 0; j < height; j++) cout << "*";
cout << endl; // cout << endl;
} // }
} //}
int main () { int main () {
auto in = input_data(); auto in = input_data();

@ -0,0 +1,26 @@
#include <iostream>
#include <vector>
#include "text.hpp"
using namespace std;
void show_histogram_text(const vector<size_t>& baskets) {
const size_t screen_width = 80;
const size_t max_asterisk = screen_width - 3 - 1;
cout.precision(4);
size_t baskets_max_count;
baskets_max_count = baskets[0];
for (size_t i : baskets) {
if (i > baskets_max_count) baskets_max_count = i;
}
for (int i = 0; i < baskets.size(); i++) {
size_t height = baskets[i];
if (baskets_max_count > max_asterisk) {
height = max_asterisk * (static_cast<double>(baskets[i]) / baskets_max_count);
}
cout << baskets[i] << "|";
for (int j = 0; j < height; j++) cout << "*";
cout << endl;
}
}

@ -0,0 +1,7 @@
#ifndef text_hpp
#define text_hpp
#include <vector>
void show_histogram_text(const std::vector<size_t>& baskets);
#endif /* text_hpp */
Загрузка…
Отмена
Сохранить