A college cafeteria manager conducted a survey to rate the quality of the food. A hundred students were asked using a scale of 1 to 10 with 1 being awful (bad) and 10 being excellent. Write a C++ program that stores the frequency of the students' answers in an integer array. The program should summarize the frequency for each rating in a report form. There are two display options the manager can display the report form or bar chart form.
#include <iostream>
#include <vector>
using namespace std;
void count_frequency(int arr[], int n)
{
vector<bool> visited(n, false);
for (int i = 0; i < n; i++) {
if (visited[i] == true)
continue;
int count = 1;
for (int j = i + 1; j < n; j++) {
if (arr[i] == arr[j]) {
visited[j] = true;
count++;
}
}
cout << "Number: "<<arr[i] << "\tFrequency: " << count << endl;
}
}
int main()
{
int n=5;
int rating[100];
int rate;
for(int i=1;i<=n;i++){
cout<<"\nEnter rating for student "<<i<<": ";
cin>>rating[i];
}
count_frequency(rating,n);
return 0;
}
Comments
Leave a comment