Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<iomanip>
- #include<algorithm>
- using namespace std;
- int main()
- {
- //The program should input each student's grade as an integer and store the grade in a vector.
- int value = 0;
- vector<int> grades;
- cout <<"Enter grades separated by white spaces (ending with a negative number): ";
- cin >> value;
- // Grades should be entered until the user enters a negative number for a grade.
- while(value!=-1)
- {
- grades.push_back(value);
- cin >> value;
- }
- cout << endl;
- //In computing the histogram, the minimum value of a grade is 0,
- int max = 0;
- //but your program should determine the maximum value entered by the user.
- for(int i=0; i<grades[i]; i++){
- if(grades[i] > max) max = grades[i];
- }
- //Use a dynamic array to store the histogram.
- int* array= new int[max+1];
- //The program should then scan through the vector and compute the histogram.
- for(int i=0; i< grades[i] ; i++)
- {
- array[grades[i]]++;
- }
- //Output the histogram to the console. Use top-down design
- for(int i=0; i<=max; i++){
- if(array[i]!=0)
- cout <<"Number of " << i <<"'s:\t" << array[i] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement