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

Complete an algorithm and a C program that accomplishes the following tasks: rea

ID: 3735687 • Letter: C

Question

Complete an algorithm and a C program that accomplishes the following tasks:

reads test scores from a repository into an ordered and numbered list

searches the ordered and numbered list for the highest test score and that test score's location in the list,

searches the ordered and numbered list for the lowest test score and that test score's location in the list,

determines the list's average test score

displays the information above to the screen... output should look something like this:

Highest score: 99 at array element number 13
        Lowest score: 31 at array element 20
        Average score: 74.12

Do not use Programmer-Created Functions

Assume that the repository does not have any test scores that are duplicated

Use this algorithm and C program as your starting point and build upon them

/*
Algorithm:
1. Link to the repository of test scores
2. Test to see if the link is unsuccessful... if true,
     go to step 2a1, if false go to step 2b1    
    2a1. Communicate that linking to the repository was unsuccessful
    2a2. Go to step 3
    2b1. Read one test score at a time and place the test
         score in an ordered and numbered list
    2b2. Continue until all 25 test scores are read and placed
         in an ordered and numbered list
    2b3. Close the link to the repository
    2b4. Go to step 3
    3. Terminate
*/

#include <stdio.h>

#define SIZE 25

int main(void)
{
    FILE *scores_ptr = NULL ;
    int scores_array[ SIZE ] ;
    int x = 0;
    
    //1. Link to the repository of test scores
    scores_ptr = fopen("/home/f/csci/teachers/test_scores.dat" , "r");

    //2. Test to see if the link is unsuccessful... if true,
    //   go to step 2a1, if false go to step 2b1    
    if(scores_ptr == NULL)
    {
          //2a1. Communicate that linking to the repository was unsuccessful
          //2a2. Go to step 3
        printf(" test_scores.dat was not properly opened. ");
    }
    else
    {
          //2b1. Read one test score at a time and place the test
          //     score in an ordered and numbered list
          //2b2. Continue until all 25 test scores are read and placed
          //     in an ordered and numbered list
       for(x = 0 ; x < SIZE ; x++ )
         {
            fscanf(scores_ptr ,"%d" , &scores_array[ x ]);
         }
        
         //2b3. Close the link to the repository
         fclose(scores_ptr);
        
         //2b4. Go to step 3
    }      
      
    //3. Terminate
    return(0);
}

Explanation / Answer

Please find my code.

#include <stdio.h>

#define SIZE 25

int main(void)
{
    FILE *scores_ptr = NULL ;
    int scores_array[ SIZE ] ;
    int x = 0;
  
    //1. Link to the repository of test scores
    scores_ptr = fopen("/home/f/csci/teachers/test_scores.dat" , "r");

    //2. Test to see if the link is unsuccessful... if true,
    //   go to step 2a1, if false go to step 2b1  
    if(scores_ptr == NULL)
    {
          //2a1. Communicate that linking to the repository was unsuccessful
          //2a2. Go to step 3
          printf(" test_scores.dat was not properly opened. ");
    }
    else
    {
          //2b1. Read one test score at a time and place the test
          //     score in an ordered and numbered list
          //2b2. Continue until all 25 test scores are read and placed
          //     in an ordered and numbered list
         for(x = 0 ; x < SIZE ; x++ )
         {
            fscanf(scores_ptr ,"%d" , &scores_array[ x ]);
         }
      
         //2b3. Close the link to the repository
         fclose(scores_ptr);
      
         //2b4. Go to step 3
    }

    // initialing min, max and average
    int max = scores_array[0], max_index = 0;    
    int min = scores_array[0], min_index = 0;
    double sum = scores_array[0];
    int i;
    for(i=1; i<SIZE; i++) {

      if(max < scores_array[i]) {
        max = scores_array[i];
        max_index = i;
      }

      if(min > scores_array[i]) {
        min = scores_array[i];
        min_index = i;
      }

      sum = sum + scores_array[i];
    }

    printf("Highest score: %d at array element number %d ",max, max_index );
    printf("Lowest score: %d at array element number %d ",min, min_index );
    printf("Average score: %lf ", sum/SIZE);

    //3. Terminate
    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