C++ : how to plot histogram

Started by
3 comments, last by trapeze 16 years, 7 months ago
#include<iostream> using namespace std; int main() { int i; int j; int k; int occurrence[10]={0,0,0,0,0,0,0,0,0,0}; int data[10]={6,14,82,42,46,32,97,44,27,68}; for (j=0; j<10; j++) { for (i=0; i<10; i++) { if ((data[j] >= 10*i) && (data[j] < 10*i+9)) occurrence++; } } cout << "occurrence # is "; for (k=0; k<10; k++) cout << occurrence[k]<<" "; } ---------------------------------------------------------- i don't know how to plot. i can't find the funtions. x-axis is 0-9,10-19,..,90-99. y-axis is the result above. also, how can i generate zero array at once for occurrence w/o typing them out ? great thx !
Advertisement
Quote:i don't know how to plot. i can't find the funtions. x-axis is 0-9,10-19,..,90-99. y-axis is the result above.


What kind of graphics, or is it text-mode only? C++ has no concept of graphics, either at language, or standard library level. So you'll need to find some way to draw or represent the histogram graphically yourself, or use some third-party library.

The simplest way is probably to use cout and print some symbol in shape of histogram.

Quote:also, how can i generate zero array at once for occurrence w/o typing them out ?


Use a for loop or std::fill.
Quote:Original post by Antheus
Quote:i don't know how to plot. i can't find the funtions. x-axis is 0-9,10-19,..,90-99. y-axis is the result above.


What kind of graphics, or is it text-mode only? C++ has no concept of graphics, either at language, or standard library level. So you'll need to find some way to draw or represent the histogram graphically yourself, or use some third-party library.

The simplest way is probably to use cout and print some symbol in shape of histogram.

Quote:also, how can i generate zero array at once for occurrence w/o typing them out ?


Use a for loop or std::fill.


thx ! i believe i can figure out the "for loop" method. however, i've no ideas for "std::fill". what's this ?
std::fill(iterator.start, iterator.end, value) or

std::fill(occurrence + 0, occurrence + 10, 0);

//been a while but i think thats right
Quote:Original post by Feralrath
std::fill(occurrence + 0, occurrence + 10, 0);


Thx ! That worked !

This topic is closed to new replies.

Advertisement