Question

Twenty students were asked to participate in a survey to rate their experience with a tutoring...

Twenty students were asked to participate in a survey to rate their experience with a tutoring center on a scale of 1 to 5 (where 1 means awful and 5 means excellent). Write a program that stores the 20 responses entered by the user in an integer array and summarize the results by displaying the number of occurrences of each response (1 to 5). As part of the solution, write and call the function calculate() with the following prototype. n1 is the size of the array of the responses and n2 is the size of the array of frequency.


void calculate(int responses[], int n1, int frequency[], int n2);


Example input/output #1:
Enter 20 responses: 1 4 5 3 5 3 5 2 4 5 2 4 5 5 3 4 5 3 3 1

Output:
Rating   Frequency
1                2
2                2
3                5
4                4
5                7

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include <stdio.h>

void calculate(int responses[], int n1, int frequency[], int n2);

int main( void ) {
int frequency[ 5 ] = { 0 };
int responses[ 20] = { 1, 4, 5, 3, 5, 3, 5, 2, 4, 5, 2, 4, 5, 5, 3, 4, 5, 3, 3, 1 };
calculate(responses, 20, frequency, 5);
return 0;
}

void calculate(int responses[], int n1, int frequency[], int n2){
   int answer,rating;
   for ( answer = 0; answer < n1; ++answer ){
frequency[ responses [ answer ] ]=frequency[ responses [ answer ] ]+1;
   }

printf( "%s%17s ", "Rating", "Frequency" );
for ( rating = 1; rating <= n2; ++rating ){
printf( "%6d%17d ", rating, frequency[ rating ] );
   }
}

Output:

Add a comment
Know the answer?
Add Answer to:
Twenty students were asked to participate in a survey to rate their experience with a tutoring...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT