Saturday 15 January 2011

histogram with dynamic array -


The question I want to put is as follows.

Write a program that the student's histogram should grade each student's grade as an integer and store it in a vector for a assignment. Grade should be entered unless a user enters -1 for grade. The program should scan through the vector and histogram should be calculated, the minimum value of a grade is 0, but your program should determine the maximum value entered by the user. Use a dynamic array to store a histogram, output the histogram in the console.

Added with an example: Input 20 30 4 20 30 30 -1 Output number is 4: 1 is 20: 2 is 30: 3

I How straight is the type coded: # include & lt; Vector & gt; using namespace std; Zero histogram (vector & lt; int & gt; input); Int main () {int i = 0; Intestine value; Of vector & lt; Int & gt; Grade; While (i> = 0) {cout & lt; & Lt; "Enter a grade for the student:"; CIN & gt; & Gt; value; Grades.push_back (value); If ((grade [i]) == (- 1)) {break; } I ++; } Histogram (grade); } Void histogram (vector & lt; int & gt; input) {}

I tried to do something for the histogram function but it failed in a terrible way. I do not know how to talk about the histogram.

I do not know if this is correct, but I did it.

  zero histogram (vector> int> input) {// announcement of a new array int aGrades [] = {0,0,0,0,0,0,0,0 , 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 , 0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}; (Std :: vector & lt; int & gt; :: iterator = input.begin (); for it! = Input.end (); ++ this) {int number = * it; // cout & lt; & Lt; Number & lt; & Lt; Endl; Aggregates [number] + = 1; // int * this; // works for integer (int grade loop = 0; grade loop & lt; 100; grade loop ++) {if (aggregation [grade loop]> gt; {cout & lt; & lt; "number of" & Lt; & lt; grade loop & lt; "'S:" & lt; agrets [grade loop] <  < / Div> 

No comments:

Post a Comment