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

Strings format #include <stdio.h> C ? Statistics Lab test scores), can be summar

ID: 3710052 • Letter: S

Question

Strings format



#include <stdio.h> C

? Statistics Lab test scores), can be summarized by a frequency distri chart. For example, if the list of test scores is: 90, 85, 100, so, s0, 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: score frequency 100 95 90 85 80 75 70 65 60 50 a) Write a C program, stats.c, that initializes an array at compile time with the test scores shown above and outputs the test scores, five per line. 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. Note that the scores are listed in decreasing value within the table. 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.

Explanation / Answer

As per your requirement the below one is solution please follow it step by step

#include <stdio.h>
#include <stdlib.h>
#define PASS_MARKS 60

/****************************************************************************************************
* function: bubbleSort
* description: bubble sort function
*/
void bubbleSort(int *, int);

/****************************************************************************************************
* function: frequency
* description: returns frequency
*/
int frequency(int *, int, int);

/****************************************************************************************************
* function: Pass_Failed
* description: calculates percent of scores
*/
void Pass_Failed(int *, int);

/****************************************************************************************************
* function: mean
* description: calculates mean of scores
*/
void mean(int *, int);

/****************************************************************************************************
* function: mode
* description: contains a printf informational for the mode of scores
*/
void mode(int *, int);

/****************************************************************************************************
* function: median
* description: calculates median of scores
*/
void median(int *, int);

int main()
{
int SIZE = 30;
int scores[] = { 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 };
int freq = 0;
int i;

printf("Original Data: ");
for (i = 0; i < SIZE; i += 5) {
printf("%d %d %d %d %d %c", scores[i], scores[i + 1], scores[i + 2], scores[i + 3], scores[i + 4], ' ');
}

bubbleSort(scores, SIZE);

printf(" Score Frequency ");
printf("------ --------- ");
freq = frequency(scores, SIZE, scores[SIZE-1]);
printf("%d %d ", scores[SIZE-1], freq);
  
for (i = SIZE-2; i > 0; i--){
if(scores[i] != scores[i+1])
{
freq = frequency(scores, SIZE, scores[i]);
printf("%d %d ", scores[i], freq);
}
}
Pass_Failed(scores, SIZE);
mean(scores, SIZE);
mode(scores, SIZE);
median(scores, SIZE);
}

void bubbleSort(int* scores, int n)
{
int swap, i, k = 0, j = 0;
  
for (i = 0 ; i < ( n - 1 ); i++)
{
for (j = 0 ; j < n - i - 1; j++)
{
if (scores[j] > scores[j+1]) //ascending order sorting
{
swap = scores[j];
scores[j] = scores[j+1];
scores[j+1] = swap;
}
}
}


}

int frequency(int *scores, int SIZE, int score){
int i;
int freq = 0;
for (i = 0; i < SIZE; i++){
if (scores[i] == score){
freq++;
}
}
return freq;
}

void Pass_Failed(int *scores, int SIZE){
int pass = 0;
float percent;
int i;
for (i = 0; i < SIZE; i++){
if (scores[i] >= PASS_MARKS){
pass++;
}
}
percent = (float)pass / (float)SIZE;
printf(" %.2f percent scores have recieved a passing score ", percent);
printf(" %.2f percent scores have recieved a failing score ", 1-percent);
}

void mean(int *scores, int SIZE){
int i, summation = 0;
float mean;
for (i = 0; i < SIZE; i++){
summation += scores[i];
}
mean = (float)summation / (float)SIZE;
printf(" The mean scores is %.2f ", mean);
}

void mode(int *scores, int SIZE)
{
//Mode calculation
  
int maxValue = 0, maxCount = 0, i, j;

for (i = 0; i < SIZE; ++i) {
int count = 0;
for (j = 0; j < SIZE; ++j) {
if (scores[j] == scores[i])
++count;
}
if (count > maxCount) {
maxCount = count;
maxValue = scores[i];
}
}

printf(" Mode is : %d ", maxValue);

}

void median(int *scores, int SIZE)
{
//Median calculation   
int i;
float median = 0;
float mid = 0;

if(SIZE%2 == 0)
{
int temp = (SIZE/2)-1;
  
for( i=0;i<SIZE;i++)
{
if(temp==i || (temp+1)==i)
{
mid=mid+scores[i];
}
}

mid=mid/2;
printf(" Median is: %.2f ",mid);
}

else
{
int temp = (SIZE/2);
for( i=0;i< SIZE;i++)
{
if(temp == i)
{
int mid = scores[i];
printf(" Median is: %d ",mid);
}
}
}

}



/* Output :

Original Data:
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     

Score       Frequency
------       ---------
100       3
95       5
90       3
85       3
80       2
75       1
70       4
65       2
60       2
55       2
50       3

0.83 percent scores have recieved a passing score

0.17 percent scores have recieved a failing score

The mean scores is 77.50

Mode is : 95

Median is: 80.00

*/