graph.cc: coding style fixes
This commit is contained in:
parent
1cc6b0c9ef
commit
f2b75f7531
36
graph.cc
36
graph.cc
@ -3,33 +3,41 @@
|
|||||||
|
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
|
|
||||||
char * getGraphByPercentage(unsigned value, unsigned len) {
|
std::string get_graph_by_percentage(unsigned value, unsigned len)
|
||||||
|
{
|
||||||
unsigned step = 0;
|
unsigned step = 0;
|
||||||
char * bars = new char[len + 1];
|
std::string bars;
|
||||||
|
|
||||||
unsigned barCount = (static_cast<float>(value) / 99.9 * len);
|
unsigned bar_count = (static_cast<float>(value) / 99.9 * len);
|
||||||
|
|
||||||
for(step; step < barCount; step++)
|
for(step; step < bar_count; step++)
|
||||||
bars[step] = '|';
|
{
|
||||||
|
bars.append("|");
|
||||||
|
}
|
||||||
for(step; step < len; step++)
|
for(step; step < len; step++)
|
||||||
bars[step] = ' ';
|
{
|
||||||
bars[len]='\0';
|
bars.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
return bars;
|
return bars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char * getGraphByValue(unsigned value, unsigned max, unsigned len) {
|
std::string get_graph_by_value(unsigned value, unsigned max, unsigned len)
|
||||||
|
{
|
||||||
unsigned step = 0;
|
unsigned step = 0;
|
||||||
char * bars = new char[len + 1];
|
std::string bars;
|
||||||
|
|
||||||
unsigned barCount = (static_cast<float>(value / (max - 0.1)) * len);
|
unsigned bar_count = (static_cast<float>(value / (max - 0.1)) * len);
|
||||||
|
|
||||||
for(step; step < barCount; step++)
|
for(step; step < bar_count; step++)
|
||||||
bars[step] = '|';
|
{
|
||||||
|
bars.append("|");
|
||||||
|
}
|
||||||
for(step; step < len; step++)
|
for(step; step < len; step++)
|
||||||
bars[step] = ' ';
|
{
|
||||||
bars[len]='\0';
|
bars.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
return bars;
|
return bars;
|
||||||
}
|
}
|
||||||
|
6
graph.h
6
graph.h
@ -1,7 +1,9 @@
|
|||||||
#ifndef GRAPH_H_
|
#ifndef GRAPH_H_
|
||||||
#define GRAPH_H_
|
#define GRAPH_H_
|
||||||
|
|
||||||
char * getGraphByPercentage(unsigned, unsigned len = 10);
|
#include <string>
|
||||||
char * getGraphByValue(unsigned, unsigned, unsigned len = 10);
|
|
||||||
|
std::string get_graph_by_percentage(unsigned, unsigned len = 10);
|
||||||
|
std::string get_graph_by_value(unsigned, unsigned, unsigned len = 10);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user