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