Question
Question Type : Write a program ----------------------------------------------------------- Write the needed code to make the program runs correctly. The following program reads (n) as the size
Question Type : Write a program
-----------------------------------------------------------
Write the needed code to make the program runs correctly.
The following program reads (n) as the size of the data set
and a symbol (ch) of type char.
Then (n) integer numbers are keyed in by the user and stored
in the array (arr).
You are expected to implement the function "displayHistogram"
that produces the results that are exactly shown in the sample
runs below.
IMPORTANT:
You must count the spaces and lines carefully. Any change in
the output, no marks will be given.
Sample Run 1:
Enter size of data: 10
Enter symbol to use : #
Enter 6 data elements : 1 2 3 4 5 6 5 4 3 2
Your input: 1,2,3,4,5,6,5,4,3,2,
Item 1 --|#
Item 2 --|##
Item 3 --|###
Item 4 --|####
Item 5 --|#####
Item 6 --|######
Item 7 --|#####
Item 8 --|####
Item 9 --|###
Item 10 --|##
Sample Run 2:
Enter size of data: 6
Enter symbol to use : @
Enter 6 data elements : 9 6 3 7 10 15
Your input: 9,6,3,7,10,15,
Item 1 --|@@@@@@@@@
Item 2 --|@@@@@@
Item 3 --|@@@
Item 4 --|@@@@@@@
Item 5 --|@@@@@@@@@@
Item 6 --|@@@@@@@@@@@@@@@
---------------------------------------------------------------*/
#include
#include
using namespace std;
const int MAXSIZE = 100;
// -------------------------------------------------------------
// Implement the displayHistogram below this comment lines
// -------------------------------------------------------------
// -------------------------------------------------------------
// You are not allowed to change anything below these comment
// lines. Any change will cause you to get 0.
// -------------------------------------------------------------
void readArray(int a[], int size){
for (int i=0;i cin >> a[i]; } void printArray(int a[], int size){ for (int i=0;i cout << a[i] << ","; cout << endl; } int main() { int arr[MAXSIZE]; char ch; int size; cerr << "Enter size of data: "; cin >> size; cerr << "Enter symbol to use : "; cin >> ch; cerr << "Enter " << size << " data elements : "; readArray(arr, size); cerr << "Your input: "; printArray(arr, size); displayHistogram(arr, size, ch); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started