code: Вынос печати гистограммы в файл
Этот коммит содержится в:
32
LABA1.cpp
32
LABA1.cpp
@@ -1,8 +1,13 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "histogram.h"
|
||||
#include "text.h"
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
Забабахать show_histogram_text в отдельный файл
|
||||
*/
|
||||
|
||||
struct Input {
|
||||
vector <double> marks;
|
||||
int NCharts = 0;
|
||||
@@ -20,33 +25,6 @@ Input input_data() {
|
||||
return in;
|
||||
};
|
||||
|
||||
void show_histogram_text(const vector<double>& marks, const vector<double>& chart) {
|
||||
int VecSize = size(marks);
|
||||
const int shift = 4, maxlen = 80;
|
||||
double interval = 0, inp = 0, i = 0, min = 0, max = 0, scale = 1;
|
||||
FindMinMax(chart, min, max);
|
||||
if ((max + shift) > maxlen) {
|
||||
scale = (max + shift) / maxlen;
|
||||
}
|
||||
for (i = 0; i < size(chart); i++) {
|
||||
if (chart[i] < 10) {
|
||||
cout << " ";
|
||||
}
|
||||
else if (9 < chart[i] && chart[i] < 100) {
|
||||
cout << " ";
|
||||
}
|
||||
cout << chart[i] << "|";
|
||||
max = (chart[i] / scale);
|
||||
if (scale != 1) {
|
||||
max -= 1;
|
||||
}
|
||||
for (int j = 0; j < max; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
Input in = input_data();
|
||||
|
||||
29
text.cpp
Обычный файл
29
text.cpp
Обычный файл
@@ -0,0 +1,29 @@
|
||||
#include "histogram.h"
|
||||
using namespace std;
|
||||
|
||||
void show_histogram_text(const vector<double>& marks, const vector<double>& chart) {
|
||||
int VecSize = size(marks);
|
||||
const int shift = 4, maxlen = 80;
|
||||
double interval = 0, inp = 0, i = 0, min = 0, max = 0, scale = 1;
|
||||
FindMinMax(chart, min, max);
|
||||
if ((max + shift) > maxlen) {
|
||||
scale = (max + shift) / maxlen;
|
||||
}
|
||||
for (i = 0; i < size(chart); i++) {
|
||||
if (chart[i] < 10) {
|
||||
cout << " ";
|
||||
}
|
||||
else if (9 < chart[i] && chart[i] < 100) {
|
||||
cout << " ";
|
||||
}
|
||||
cout << chart[i] << "|";
|
||||
max = (chart[i] / scale);
|
||||
if (scale != 1) {
|
||||
max -= 1;
|
||||
}
|
||||
for (int j = 0; j < max; j++) {
|
||||
cout << "*";
|
||||
}
|
||||
cout << "\n";
|
||||
}
|
||||
};
|
||||
8
text.h
Обычный файл
8
text.h
Обычный файл
@@ -0,0 +1,8 @@
|
||||
#ifndef TEXT_H_INCLUDED
|
||||
#define TEXT_H_INCLUDED
|
||||
#include "text.cpp" //Âîçìîæíî, êîñòûëü. Íî áåç ýòîãî íå ðàáîòàåò!
|
||||
#include <vector>
|
||||
|
||||
void show_histogram_text(const vector<double>& marks, const vector<double>& chart);
|
||||
|
||||
#endif // TEXT_H_INCLUDED
|
||||
Ссылка в новой задаче
Block a user