Functions for generating vertical graphs

This commit is contained in:
l0ner 2014-04-14 21:46:32 +02:00
parent b0ab6ea57a
commit ccf33e2a26
2 changed files with 43 additions and 0 deletions

36
graph.cc Normal file

@ -0,0 +1,36 @@
#include <string>
#include <cstring>
#include "graph.h"
char * getGraphByPrecentage(unsigned value, unsigned len) {
unsigned step = 0;
char * bars = new char[len + 1];
unsigned barCount = (float(value) / 100 * len);
for(step; step < barCount; step++)
bars[step] = '|';
for(step; step < len; step++)
bars[step] = ' ';
bars[len]='\0';
return bars;
}
char * getGraphByValue(unsigned value, unsigned max, unsigned len) {
unsigned step = 0;
char * bars = new char[len + 1];
unsigned barCount = (float(value) / float(max) * len);
for(step; step < barCount; step++)
bars[step] = '|';
for(step; step < len; step++)
bars[step] = ' ';
bars[len]='\0';
return bars;
}

7
graph.h Normal file

@ -0,0 +1,7 @@
#ifndef GRAPH_H_
#define GRAPH_H_
char * getGraphByPrecentage(unsigned, unsigned len = 10);
char * getGraphByValue(unsigned, unsigned, unsigned len = 10);
#endif