Please help me with this program for C++ Histogram This assignment will help you
ID: 3566638 • Letter: P
Question
Please help me with this program for C++
Histogram This assignment will help you practice programming with FLTK. You can mainly use the tools you have encountered so far and which are available in the sample codes you have downloaded from the book?s website. The scenario is that you want to design a histogram from a set of grades for a class of students. The number of students should be given by the user. The grades in this scenario are also supposed to be given by the user, but for convenience the program should give the user the option to randomly generate them. Then, your program should gather the grades into ranges of length 10 (i.e. [0.10), [10.20), etc) and for each range it should count the number of students that fall into that range. The histogram represents these values, so it should have 10 columns. Together with the histogram you should draw a line to connect the top of each column. The colors of the columns, the line, the axes, and the labels should be chosen by the user. The label for each axis should be informative as to what the axis represents as you can see in the picture below. To complete this assignment you may want to use a vector to store multiple rectangles. There are certain issues with this, though, which are not analyzed further in this assignment. Fortunately there is a solution. You can use Vector_ref to store these rectangles, which is used in file chapter.13.10-2.cpp.Explanation / Answer
#include <iostream.h>
using namespace std;
int bin_array [3];
int i;
int j;
int data;
int main()
{
int grade,bin_array[4];
while (std::cin>> grade && grade > 0 && grade < 40) {
if (grade >= 1 && grade <= 9)
++bin_array[0];
else if (grade >= 10 && grade <= 19)
++bin_array[1];
else if (grade >= 20 && grade <= 29)
++bin_array[2];
else if (grade >= 30 && grade <= 39)
++bin_array[3];
std::cout<<"1-9: ";
for (int j = 0; j < bin_array[0]; j++)
std::cout<<'*';
std::cout<<' ';
std::cout<<"10-19: ";
for (int j = 0; j < bin_array[1]; j++)
std::cout<<'*';
std::cout<<' ';
std::cout<<"20-29: ";
for (int j = 0; j < bin_array[2]; j++)
std::cout<<'*';
std::cout<<' ';
std::cout<<"30-39: ";
for (int j = 0; j < bin_array[3]; j++)
std::cout<<'*';
std::cout<<' ';
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.