From ccf33e2a26368eceec30443c4ceb6420113ac384 Mon Sep 17 00:00:00 2001 From: l0ner Date: Mon, 14 Apr 2014 21:46:32 +0200 Subject: [PATCH] Functions for generating vertical graphs --- graph.cc | 36 ++++++++++++++++++++++++++++++++++++ graph.h | 7 +++++++ 2 files changed, 43 insertions(+) create mode 100644 graph.cc create mode 100644 graph.h diff --git a/graph.cc b/graph.cc new file mode 100644 index 0000000..1a9d2c9 --- /dev/null +++ b/graph.cc @@ -0,0 +1,36 @@ +#include +#include + +#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; +} + diff --git a/graph.h b/graph.h new file mode 100644 index 0000000..4cc550b --- /dev/null +++ b/graph.h @@ -0,0 +1,7 @@ +#ifndef GRAPH_H_ +#define GRAPH_H_ + +char * getGraphByPrecentage(unsigned, unsigned len = 10); +char * getGraphByValue(unsigned, unsigned, unsigned len = 10); + +#endif