Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Twenty students were asked to rate on the scale from 1 to 10 the quality of the

ID: 3874801 • Letter: T

Question

Twenty students were asked to rate on the scale from 1 to 10 the quality of the food in the student food court with 1 being "awful" and 10 being "excellent".   The responses are stored in the survey.txt file.   Read in these responses into an array and determine the frequency of each rating. Display the frequencies as a histogram as shown below:

*

**
***
**
****
**
***
**
*

The program should run in visual studio and should be in the form of c++

these are the numbers in the survery.txt file

3

5

4

6

8

10

3

4

1

7

6

6

8

9

8

5

9

6

7

4

Rating Frequency 1
2
3
4
5
6
7
8
9
10

*

**
***
**
****
**
***
**
*

The program should run in visual studio and should be in the form of c++

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char const *argv[])
{
   int freq[10];

   //initialize freq to 0
   for (int i = 0; i < 10; i++)
       freq[i] = 0;

   //Handle input file
   ifstream in;
   in.open("survey.txt");
   //read file and update freq
   int item;
   while (!in.eof()) {
       in >> item;
       freq[item - 1]++;
   }

   //print histogram
   cout << "Ratng |Frequency |" << endl << "--------|---------------|" << endl;
   for (int i = 0; i < 10; ++i) {
       cout << i+1 << " |";
       for (int j = 0; j < freq[i]; ++j) {
           cout << "*";
       }
       cout << endl;
   }
   cout << "--------|---------------|" << endl
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote