Answer to Question #223520 in C++ for Sunny d

Question #223520

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.


1
Expert's answer
2021-08-05T17:51:25-0400


#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS