Hey peeps, i am just another lost programmer here looking for some good old fashion help, pertaining to a histogram program.
If there is anyone out there that can follow me as to what i will me explaining i would like it if u'd step in make
a suggestion or plainly help me solve this problem. Are u ready kids....GRRRRRRRREAT!!!!
I want to be able to use the getData algorithm to read the file and store the data in an array, (still with me....GOOD).
Then be able to use the printData algorithm to print the data in the array(asleep yet...GREAT). Thirdly, using the
makeFrequency algorithm to examine the data in the array, one element at a time, then add 1 to the corresponding element ina
frequency array based on the data value (ya'll still there right?...FABULOUS).
Finally,use makeHistogram algorithm to print out a vertical histogram using asterisks for each occurrence of an element.
Uh like...for eg. if there were like five value 1s and eight value 2s in the data, it would print out:
1: *****
2: ********
P.S. This is an example of the program but i am somehow going at it wrong because of the books i am using. So if any one can
help me please, and tell me what i need to do to better it, i would really appreciate it. Thanx a million.:-)
#include <iostream>
#include <ctime>
using namespace std;
void display( int[], int );
int main()
{
const int arraysize = 10;
srand( time( 0 ) );
int val, array[ arraysize ] = { 0 }; // initialize the ten element "array" to zero
for( int i = 0; i <= 500; i++)
{
val = 0 + rand() % 99;
array[ val / 10 ] = val;
}
display( array, arraysize );
}//end main
void display( int a[], int arraysize )
{
int minimum = 0,maximum = 9; // Declare and initialize maximum and minimum of the first range
for( int i = 0; i < arraysize; i++ )
{
cout << minimum << "-" << maximum << " " << a[ i ]; //output range
for( int j = 0; j < a[ i ]; j++ )
cout << "*"; //output frequency
cout << endl << endl;
minimum = minimum + 10; // Increment minimum by 10
maximum = maximum + 10; // Increment maximuim by 10
}
system("PAUSE");
return;
}