code:first code laba 4
Этот коммит содержится в:
3
main.cpp
3
main.cpp
@@ -35,8 +35,7 @@ int main()
|
|||||||
max_count=x;
|
max_count=x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
vector<size_t> procent = make_histogram_proc(in.numbers, in.bin_count, bins);
|
|
||||||
show_histogram_text(bins,in.bin_count,in.numbers,max_count);
|
show_histogram_text(bins,in.bin_count,in.numbers,max_count);
|
||||||
//show_histogram_svg(bins, max_count,procent);
|
//show_histogram_svg(bins, max_count);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
10
svg.cpp
10
svg.cpp
@@ -20,8 +20,8 @@ svg_text(double left, double baseline, std::string text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
svg_proc(double left, double baseline,size_t procent) {
|
svg_proc(double left, double baseline) {
|
||||||
std::cout << "<text x='"<< left <<"' y='"<< baseline <<"'>"<< procent <<"%</text>";
|
std::cout << "<text x='"<< left <<"' y='"<< baseline<<"</text>";
|
||||||
}
|
}
|
||||||
|
|
||||||
void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fill = "green"){
|
void svg_rect(double x, double y, double width, double height,std::string stroke = "black", std::string fill = "green"){
|
||||||
@@ -33,7 +33,7 @@ svg_end() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
show_histogram_svg(std::vector<size_t> bins,size_t max_count, const std::vector<size_t> procent) {
|
show_histogram_svg(std::vector<size_t> bins,size_t max_count) {
|
||||||
const auto IMAGE_WIDTH = 400;
|
const auto IMAGE_WIDTH = 400;
|
||||||
const auto IMAGE_HEIGHT = 300;
|
const auto IMAGE_HEIGHT = 300;
|
||||||
const auto TEXT_LEFT = 20;
|
const auto TEXT_LEFT = 20;
|
||||||
@@ -55,7 +55,7 @@ show_histogram_svg(std::vector<size_t> bins,size_t max_count, const std::vector<
|
|||||||
const auto TEXT_LEFT_PROCENT = SCALE+TEXT_WIDTH+20;
|
const auto TEXT_LEFT_PROCENT = SCALE+TEXT_WIDTH+20;
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||||
svg_proc(TEXT_LEFT_PROCENT, top + TEXT_BASELINE,procent[i]);
|
svg_proc(TEXT_LEFT_PROCENT, top + TEXT_BASELINE);
|
||||||
|
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}}
|
}}
|
||||||
@@ -65,7 +65,7 @@ show_histogram_svg(std::vector<size_t> bins,size_t max_count, const std::vector<
|
|||||||
const auto TEXT_LEFT_PROCENT = (max_count*SCALE)+TEXT_WIDTH+20;
|
const auto TEXT_LEFT_PROCENT = (max_count*SCALE)+TEXT_WIDTH+20;
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bins[i]));
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
|
||||||
svg_proc(TEXT_LEFT_PROCENT, top + TEXT_BASELINE,procent[i]);
|
svg_proc(TEXT_LEFT_PROCENT, top + TEXT_BASELINE);
|
||||||
|
|
||||||
top += BIN_HEIGHT;
|
top += BIN_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|||||||
2
svg.h
2
svg.h
@@ -5,6 +5,6 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
void
|
void
|
||||||
show_histogram_svg(std::vector<size_t> bins,size_t max_count, const std::vector<size_t> procent);
|
show_histogram_svg(std::vector<size_t> bins,size_t max_count);
|
||||||
|
|
||||||
#endif // SVG_H_INCLUDED
|
#endif // SVG_H_INCLUDED
|
||||||
|
|||||||
8
text.cpp
8
text.cpp
@@ -12,8 +12,6 @@ void show_histogram_text(const std::vector<size_t> bins, size_t bin_count, const
|
|||||||
size_t procent=100;
|
size_t procent=100;
|
||||||
for(size_t i = 0;i<(bin_count-1);i++){
|
for(size_t i = 0;i<(bin_count-1);i++){
|
||||||
double number = numbers.size();
|
double number = numbers.size();
|
||||||
double proc=(bins[i]/number)*100;
|
|
||||||
procent -=round(proc);
|
|
||||||
printf("%3d:", bins[i]);
|
printf("%3d:", bins[i]);
|
||||||
for(size_t j = 0;j<bins[i];j++)
|
for(size_t j = 0;j<bins[i];j++)
|
||||||
{
|
{
|
||||||
@@ -23,7 +21,6 @@ void show_histogram_text(const std::vector<size_t> bins, size_t bin_count, const
|
|||||||
{
|
{
|
||||||
cout<<" ";
|
cout<<" ";
|
||||||
}
|
}
|
||||||
printf("%3.0f%%",proc);
|
|
||||||
cout<<endl;
|
cout<<endl;
|
||||||
}
|
}
|
||||||
//procent=Math.round(procent);
|
//procent=Math.round(procent);
|
||||||
@@ -32,9 +29,4 @@ void show_histogram_text(const std::vector<size_t> bins, size_t bin_count, const
|
|||||||
{
|
{
|
||||||
cout<<"*";
|
cout<<"*";
|
||||||
}
|
}
|
||||||
for(size_t g=0;g<(max_count-bins[bin_count-1]);g++)
|
|
||||||
{
|
|
||||||
cout<<" ";
|
|
||||||
}
|
|
||||||
printf("%3d%%",procent);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user