Write a program using the function void bar_chart(double values[], int size) tha
ID: 3637087 • Letter: W
Question
Write a program using the functionvoid bar_chart(double values[], int size)
that displays a bar chart of the values in values, using asterisks, like this:
**********************
****************************************
****************************
**************************
**************
You may assume that all values in values are positive or negative. First figure out the maximum
value in values. That value’s bar should be drawn with 40 asterisks. Shorter bars
should use proportionally fewer asterisks.
Explanation / Answer
This is actually not as scary as it looks. This will require two passes through the input values. The first pass you will identify the largest value and the smallest value. The second pass will then draw the bar chart, scaling the smallest value to zero asterisks and the largest value to one asterisk. So that being said: If you haven't seen C++ strings yet, don't worry. Instead of using the substr() method to extract the asterisks, you can do a simple "for" loop like: for( i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.