Functions for generating vertical graphs
This commit is contained in:
parent
b0ab6ea57a
commit
ccf33e2a26
36
graph.cc
Normal file
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
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
|
Loading…
Reference in New Issue
Block a user