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

Need this coded in C, no C++ functions can be used. Can include stdio.h, stdlib.

ID: 3685869 • Letter: N

Question

Need this coded in C, no C++ functions can be used. Can include stdio.h, stdlib.h, string.h, and ctype.h.

1. The program should print "COP 2220 Project 4: " with a blank line before and after. 2. Then it should prompt the user for the input file name of the file containing the data to sort 3. If the program can't open the file or if no file name is entered (Ad is entered on Linux or *z- Enter on Windows for EOF), it should print an error message and exit. 4. The file will contain numbers that could be positive or negative integers or floating point numbers four numbers to a line, separated by commas 5. The program should only handle the first 88 valid numbers in the file 6. The program should read the numbers from the file into a single dimensional array and then sort the array in ascending order (lowest to highest) using the bubble sort 7. If the program encounters a non-numeric value in the file, it should flush that input line in the file, print an error message and go to the next line. It should not use any numbers from that line 8. The program should print the sorted list of numbers, 8 numbers to a line in columns 9 characters wide with 2 digits to the right of the decimal point. 9. After printing the sorted list, it should print: There were lines found in file There were valid numbers found in file The smallest number found was: The average of the values is The largest number found was: There were negative numbers in the file o o o The average should be calculated as a double 10. If there are no valid lines in the file, the program should only print the following lines o There were 0 lines found in file o There were 0 valid numbers found in file 11. Include comments in your code to explain what the code does. Make sure to have comments on the program and for each function 12. See the examples below for spacing and formatting 13. Your program should include at least four functions called from main (in addition to main) that vou will define 14. Your program should not use global variables except an optional global debug fla!g

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

int main()

{

   int ch, file_name[25];

   FILE *fp;

   printf("Enter the name of file you wish to see ");

   gets(file_name);

   fp = fopen(file_name,"r"); // read mode

   if( fp == NULL )

   {

      perror("Error while opening the file. ");

      exit(EXIT_FAILURE);

   }

   int integers[100],array[100];

    int count=0;

    int num;

    while(fscanf(fp, "%d", &num) > 0)

   {

        integers[count] = num;

        count++;

    }

printf("number of elements in text file are : %d",count);

printf("array elements are: ");

for ( int j = 0 ; j < i ; j++ )

     printf("%d ", integer[j]);

int c,d,swap;

for (c = 0 ; c < ( count - 1 ); c++)

{

    for (d = 0 ; d < count - c - 1; d++)

    {

     if (array[d] > array[d+1]) /* For decreasing order use < */

      {

        swap       = array[d];

        array[d]   = array[d+1];

        array[d+1] = swap;

      }

    }

}

printf("Sorted list in ascending order: ");

for ( c = 0 ; c < n ; c++ )

     printf("%d ", array[c]);

int no_lines=0;

char sample_chr;

            sample_char = getc(fp);

    while (sample_chr != EOF) {

       

        if (sample_chr == '')

        {   

           

            no_lines=no_lines+1;

        }

       

        sample_chr = getc(fp);

    }

printf("There are %d lines in %s

    ", no_lines, file_name);

int big=integer[0],k;

for(k=1;k<count;k++){

      if(big<array[k])

           big=array[k];

}

printf("Largest element: %d",big);

int small=integer[0];

for(k=1;k<count;k++){

      if(small>array[k])

           small=array[k];

}

printf("Smallest element: %d",small);

int i,m=0;

for (i = 0; i < count; i++)

    {

        if (array[i] < 0)

        {

           int negative_sum = negative_sum + array[i];

            m++;

        }

        else if (array[i] > 0)

        {

            int positive_sum = positive_sum + array[i];

        }

        else if (array[i] == 0)

        {

            ;

        }

        int total = total + array[i] ;

    }

float average = total / num;

    printf(" Sum of all negative numbers = %d ", negative_sum);

    printf("Sum of all positive numbers = %d ", positive_sum);

    printf(" Average of all input numbers = %.2f ", average);

printf("number of negative numbers = %d",m);

    fclose(fp);

   return 0;

}

note-the above code can help to answer the given question.

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