Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION 5 The main program below is missing the function histogramPlot . The pr

ID: 3819586 • Letter: Q

Question

QUESTION 5

The main program below is missing the function histogramPlot. The program generate the example output for the example array values provided.

int main (void) {

            cons tint size = 15;

            int data[size] = {1, 2, 3, 0, 1, 2, 3, 6, 7, 5, 9, 1, 1, 3, 5};

            histogramPlot(data, size);

      system(“PAUSE”); return 0;

}

example output:

0 :X

1 :XXXX

2 :XX

3 :XXX

4 :

5 :XX

6 :X

7 :X

8 :

9 :X

10 :

You must create a function histogramPlot that prints out a simple histogram of the values in the array for integers 0 through 10 inclusive and prints out X for each occurrence of each value. ie. In the example array data, the value 1 occurs 4 times and the value 8 does not occur. Your function must support an array of any size and integer contents. If the array had values outside the 0=10 range, they should be ignored.

Hint: To receive full marks and for the simplest solution a second function that retunes the number of occurrences of a value in an array must be created and used.

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;
void histogramPlot(int data[], int size);
int main (void) {
   const int size = 15;
   int data[size] = {1, 2, 3, 0, 1, 2, 3, 6, 7, 5, 9, 1, 1, 3, 5};
   histogramPlot(data, size);
}

void histogramPlot(int data[], int size){
   int count[11];
   int i;
   for(i=0; i<11; i++){
       count[i] = 0;
   }

   for(i=0; i<size; i++){
       int pos = data[i];
       if(pos>=0 && pos<=10){
           count[pos]++;
       }
   }
   for(i=0; i<=10; i++){
       int freq = count[i];
       int j;
       cout << i<<" : ";
       for(j=0; j<freq; j++){
           cout << "X";
       }
       cout << endl;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote