code: пункт 3.1 разделение программы
Этот коммит содержится в:
@@ -1,4 +1,5 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "histogram.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
std::vector<size_t>
|
||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||
std::vector<std::size_t>
|
||||
make_histogram(const std::vector<double>& numbers, std::size_t bin_count);
|
||||
|
||||
#endif // HISTOGRAM_H_INCLUDED
|
||||
|
||||
33
main.cpp
33
main.cpp
@@ -1,11 +1,11 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 4;
|
||||
|
||||
|
||||
struct Input {
|
||||
vector<double> numbers;
|
||||
@@ -32,35 +32,6 @@ Input input_data() {
|
||||
return in;
|
||||
};
|
||||
|
||||
void show_histogram_text(const vector<size_t> &bins){
|
||||
size_t maxbin = bins[0];
|
||||
for (size_t i=1; i < bins.size(); i++){
|
||||
if (maxbin < bins[i]){
|
||||
maxbin = bins[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (maxbin <= MAX_ASTERISK){
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
cout.width(4);
|
||||
cout << bins[i] << "|";
|
||||
for (size_t j = 0; j < bins[i]; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
cout.width(4);
|
||||
cout << bins[i] << "|";
|
||||
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin));
|
||||
for (size_t j = 0; j < height; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
int main(){
|
||||
Input in = input_data();
|
||||
|
||||
|
||||
38
text.cpp
Обычный файл
38
text.cpp
Обычный файл
@@ -0,0 +1,38 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "text.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 4;
|
||||
|
||||
void show_histogram_text(const vector<size_t> &bins){
|
||||
size_t maxbin = bins[0];
|
||||
for (size_t i=1; i < bins.size(); i++){
|
||||
if (maxbin < bins[i]){
|
||||
maxbin = bins[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (maxbin <= MAX_ASTERISK){
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
cout.width(4);
|
||||
cout << bins[i] << "|";
|
||||
for (size_t j = 0; j < bins[i]; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < bins.size(); i++) {
|
||||
cout.width(4);
|
||||
cout << bins[i] << "|";
|
||||
size_t height = static_cast<size_t>(MAX_ASTERISK * (static_cast<double>(bins[i]) / maxbin));
|
||||
for (size_t j = 0; j < height; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
text.h
Обычный файл
9
text.h
Обычный файл
@@ -0,0 +1,9 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::size_t>
|
||||
show_histogram_text(const std::vector <std::size_t>& bins);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
||||
Ссылка в новой задаче
Block a user