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

Write a C program to input the scores and print out the scores 5 per line. Sort

ID: 675346 • Letter: W

Question

Write a C program to input the scores and print out the scores 5 per line. Sort the scores in ascending order and output the scores. Calculate and print a frequency distribution chart. Output % of passing and failing test scores to the nearest tenth. Calculate and print mean, mode, median to the nearest tenthOutput should be sent to a csis.txt output file.

So I started this assignment but the code would not build and I'm getting a million errors (complete noob) :) If anyone could show me how to do it correctly that would be great. Thanks!

Here's my failed attempt to do it:

01 #include <stdio.h>

Explanation / Answer

Too many errors due c cyntax issues. I wrote sort and frequency calculations methods. I completed all the functions except writing in a file.

#include <stdio.h>
#include <stdlib.h>
// Stats Lab

void printTestScores(int testScores[], int numberOfScores);
void printTestScoresInAscendingOrder(int testScores[], int numberOfScores);
void printTestScoresAndFrequency(int testScores[], int numberOfScores);
void printPercentagePassingFailingGrades(int testScores[], int numberOfScores);
void printMeanModeMedianTestScores(int testScores[], int numberOfScores);

FILE *csis;
double greatestFrequencyScore = 0;

int main(void) {
   csis = fopen("csis.txt", "w");

   int numberOfScores = 30;
   int testScores[] = {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};

   printTestScores(testScores, numberOfScores);
   printTestScoresInAscendingOrder(testScores, numberOfScores);
   printTestScoresAndFrequency(testScores, numberOfScores);
   printPercentagePassingFailingGrades(testScores, numberOfScores);
   printMeanModeMedianTestScores(testScores, numberOfScores);

   fclose(csis);

   return 0;
}


void sort(int testScores[], int numberOfScores) {
   int i = 0, j = 0;
   int temp;
   for (i = 0; i < numberOfScores; i++) {
       for (j = 0; j < numberOfScores-1; j++) {
           if(testScores[j+1] < testScores[j]) {
               temp = testScores[j];
               testScores[j] = testScores[j+1];
               testScores[j+1] = temp;
           }
       }
   }
}

void printTestScores(int testScores[], int numberOfScores) {
   int i;
   for (i = 0; i <= numberOfScores - 1; i++)
   {
       printf("%d ",testScores[i]);
       if((i+1) % 4 == 0)
           printf(" ");
   }
   printf(" ");
}

void printTestScoresInAscendingOrder(int testScores[], int numberOfScores) {
   sort (testScores, numberOfScores);


   int i;
   for (i = 0; i <= numberOfScores - 1; i++)
   {
       printf("%d ",testScores[i]);
       if((i+1) % 4 == 0)
           printf(" ");
   }
   printf(" ");
}

void printTestScoresAndFrequency(int testScores[], int numberOfScores) {
   printf(" Value          Frequency ");

   int i , j;

   int frequency[numberOfScores];
   double scores[numberOfScores]; //this is max limit

   int index = 0;
   for (i = 0; i <= numberOfScores - 1; i++)
   {
       frequency[i] = 0;
       scores[i] = 0;

       //printf testScores [i], frequency ;
   }

   for (i = 0; i <= numberOfScores - 1; i++)
   {

       for (j = 0; j < index; j++) {
           if(testScores[i] == scores[j]) {
               frequency[j] = frequency[j]+1;
               break;
           }
       }

       //first time
       if(j == index) {
           frequency[index] = frequency[j]+1;
           scores[index] = testScores[i];
           index++;
       }

   }

   greatestFrequencyScore = 0;

   int freq = 0;
   for (j = 0; j < index; j++) {
       printf("%f           %d ",scores[j], frequency[j]);
       if(frequency[j] > freq ) {
           freq = frequency[j];
           greatestFrequencyScore = scores[j];
       }

   }
   printf(" ");
}

void printPercentagePassingFailingGrades(int testScores[], int numberOfScores)
{
   double passingTestScores = 0;
   double failingTestScores = 0;
   int i;

   for (i = 0; i <= numberOfScores - 1; i++) {

       if (testScores[i] >= 60)
           passingTestScores ++;
       else if (testScores[i] < 60)
           failingTestScores ++;
   }

       printf ("Percentage of passing scores = %f ", (passingTestScores * 100 / numberOfScores));
       printf ("Percentage of failing scores = %f ", (failingTestScores * 100 / numberOfScores));
   printf(" ");
}

void printMeanModeMedianTestScores(int testScores[], int numberOfScores) {

   int i;
   double sumOfScores = 0;
   for (i = 0; i <= numberOfScores - 1; i++) {

       sumOfScores = sumOfScores + testScores[i];
   }


   double averageOfTwoMiddleNumbers = 0;

   if(numberOfScores % 2 == 0)
       averageOfTwoMiddleNumbers = (double)(testScores[numberOfScores/2]+ testScores[numberOfScores/2+1]) /2.0;

   printf ("Mean of test scores = %f " ,sumOfScores / numberOfScores);

   printf ("Mode of test scores = %f ", greatestFrequencyScore);

   printf ("Median of test scores = %f " ,averageOfTwoMiddleNumbers);
   printf(" ");

}

-----------------output-------------------------

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
50 50 50 55
55 60 60 65
65 70 70 70
70 75 80 80
85 85 85 90
90 90 95 95
95 95 95 100
100 100

Value          Frequency
50.000000           3
55.000000           2
60.000000           2
65.000000           2
70.000000           4
75.000000           1
80.000000           2
85.000000           3
90.000000           3
95.000000           5
100.000000           3

Percentage of passing scores = 83.333333
Percentage of failing scores = 16.666667

Mean of test scores = 77.500000
Mode of test scores = 95.000000
Median of test scores = 82.500000

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