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

A set of data (test scores), can be summarized by a frequency distribution chart

ID: 3686098 • Letter: A

Question

A set of data (test scores), can be summarized by a frequency distribution chart. For example, if the list of test scores is:

90 85 100 50 50 85 60 70 55 55 80 95 70 60 95

80 100 75 70 95 90 90 70 95 50 65 85 95 100 65

then the frequency distribution chart looks like the one below:

value           frequency

------           ------------

100                3          

95                5

90                3

85                3

80                2

75                1

70                4

65                2

60                2

55                2

50                3


a) Write a C program to input the scores above and print out the scores, five per line. Note that you should initialize the array at declaration time and also use size 1000 for the array size.

b) Sort the test scores into ascending order and output the scores, five per line.

c) Calculate and print out the frequency distribution chart as shown above.

d) Output the percentage of passing and failing test scores to the nearest tenth. Scores below 60 are failing.

e) Calculate and print out the mean of the test scores to the nearest tenth.

f) Print out the mode of the test scores.

g) The median of a list of numbers if that element such that when the numbers are arranged in ascending or descending order, half the elements lie above it and half below. This can happen only when there are an odd numbers of elements in the list. If the array contains an even number of items, the median is the average of the two numbers in the middle (to the nearest tenth). Your program should output the median of the test scores given to the nearest tenth. (Note: Your program should determine on its own whether there is an odd or even number of test scores).


Points to Remember:

Make sure you are creating a C program and not a C++ program

Each section of the assignment should be designed within its own function, passing parameters as necessary.

Please make sure to do all the parts (a-g) of the assignment

Explanation / Answer

#include <stdio.h>
#include<stdlib.h>
#include<math.h>
int cmpfunc (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}
int readscores(int arr[])
{
int a,i;
printf("Number of test scores given:");
scanf("%d",&a);
for(i=0;i<a;i++)scanf("%d",&arr[i]);
return a;
}
void print(int arr[],int len)
{
int i;
for(i=0;i<len;i++)
{
printf("%d ",arr[i]);
if((i+1)%5==0)
{ printf(" ");}
}
printf(" ");
}
void sort(int arr[],int len)
{
qsort(arr,len, sizeof(int), cmpfunc);   
print(arr,len);
}
int *freq(int arr[],int len)
{
int *count = (int *)malloc(sizeof(int)*101);
int i;
for(i=0;i<101;i++)
{
count[i]=0;
}
for(i=0;i<len;i++)
{
count[arr[i]]++;
}
printf("value frequency ");
printf("------ ------------ ");
for(i=100;i>=0;i--)
{
if(count[i]>0)
{
printf("%d %d ",i,count[i]);
}
}
return count;
}
float roundr(float a)
{
a = a*10;
a = a+0.5;
int l = a;
return (l*1.0)/10;
}
void pass(int arr[],int len)
{
int i;
int pass=0,fail=0,total;
for(i=0;i<len;i++)
{
if(arr[i]<60)fail++;
else pass++;
}
total = fail+pass;
printf("Pass percentage is %.1f ",roundr(pass*100.0/total));
printf("Fail percentage is %.1f ",roundr(fail*100.0/total));
return;
}
void mean(int arr[],int len)
{
int i;
int sum=0;
for(i=0;i<len;i++)
{
sum+=arr[i];
}
  
printf("The mean is %f ",sum*1.0/len);
return;
}
void mode(int *count)
{
int max=1,i;
for(i=1;i<101;i++)
{
if(count[i]>count[max])max=i;
}
printf("The mode is %d ",max);
return;
}
void median(int arr[],int len)
{
float ans;
if(len%2==0)
{
ans = arr[len/2];
}
else
{
ans = arr[len/2]+arr[len/2+1];
ans = ans/2;
}
printf("The median is %f ",ans);
return;
}
int main(void) {
   // your code goes here
   int i;
   int arr[1000],len=0,*count;
  
   len=readscores(arr);
   print(arr,len);
   sort(arr,len);
   count=freq(arr,len);
   pass(arr,len);
   mean(arr,len);
   mode(count);
   median(arr,len);
   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