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

Write a C program NOT C++ that reads in test grades (0.0 to 100.0) from a file c

ID: 3665458 • Letter: W

Question

Write a C program NOT C++ that reads in test grades (0.0 to 100.0) from a file called "in.dat" located in the same directory from which your executable program will be run. The file "in.dat: will contain the test grades as formatted values, one-grade-per-line. Your program will create a file called "out.dat" in that same directory. The file "out.dat" will list the test grades with the grade letter (A-F) next to it, ( one-per-line). The test grade should be formatted to be right-justified within 5 spaces with 1 digit past the decimal point, there should be 5 blank spaces, and then the letter grade should be printed left-justified within 2-spaces. For example, the output file might be

The grade ranges are as follows.

If a test grade is exactly at the boundary between two grades, the test grade is assigned the higher of the two letter grades. In the output file, after the grades, print the number of students receiving each grade. For example:

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>

int countlines(char *filename)
{
printf("file name is %s",filename);
// count the number of lines in the file called filename                                   
FILE *fp = fopen(filename,"r");
int ch=0;
int lines=0;

if (fp == NULL)
return 0;
lines++;

while(!feof(fp))
{
ch=fgetc(fp);
if(ch==' ')
{
lines++;   
}
}
return lines-1;
}

int main(int argc,char **argv)
{
FILE *myfile;


FILE *fptr;

   char ch[20];


myfile=fopen("in.dat","r");
int lines=countlines(argv[1]);
printf("size of file is %d ",lines);
int *numberArray=(int*)malloc(sizeof(int));
// fptr=fopen("out.dat","w");

   if(fptr==NULL){
      printf("Error your file is not correct!");
      exit(1);
   }

    int i;

    for (i = 0; i < lines; i++)
    {
   
        fscanf(myfile, "%d", &numberArray[i]);
    }

    for (i = 0; i < lines; i++)
    {
        printf("This is the start of the fileeeee ");
    if(numberArray[i]>=94&&numberArray[i]<=100)
    {
    fptr=fopen("out.dat","a");
        printf("Inside ");
    sprintf(ch,"%d A",numberArray[i]);
   fprintf(fptr,"%s",ch);
    fclose(fptr);
    }
    else if(numberArray[i]>=90&&numberArray[i]<94)
    {
    fptr=fopen("out.dat","a");
        printf("Inside2 ");
    sprintf(ch,"%d A-",numberArray[i]);
   fprintf(fptr,"%s",ch);
    fclose(fptr);
    }
    else if(numberArray[i]>=86&&numberArray[i]<90)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d B+",numberArray[i]);
   fprintf(fptr,"%s",ch);
fclose(fptr);
    }
    else if(numberArray[i]>=82&&numberArray[i]<86)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d B",numberArray[i]);
   fprintf(fptr,"%s",ch);
fclose(fptr);
    }
   
       else if(numberArray[i]>=78&&numberArray[i]<82)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d B-",numberArray[i]);
   fprintf(fptr,"%s",ch);
   fclose(fptr);
    }
    else if(numberArray[i]>=74&&numberArray[i]<78)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d C+",numberArray[i]);
   fprintf(fptr,"%s",ch);
fclose(fptr);
    }
    else if(numberArray[i]>=70&&numberArray[i]<74)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d C",numberArray[i]);
   fprintf(fptr,"%s",ch);
fclose(fptr);
    }
   
       else if(numberArray[i]>=66&&numberArray[i]<70)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d C-",numberArray[i]);
   fprintf(fptr,"%s",ch);
    fclose(fptr);
    }
    else if(numberArray[i]>=62&&numberArray[i]<66)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d D+",numberArray[i]);
   fprintf(fptr,"%s",ch);
fclose(fptr);
    }
    else if(numberArray[i]>=58&&numberArray[i]<62)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d D",numberArray[i]);
   fprintf(fptr,"%s",ch);
fclose(fptr);
    }
   
   
    else if(numberArray[i]>=54&&numberArray[i]<58)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d D-",numberArray[i]);
   fprintf(fptr,"%s",ch);
    fclose(fptr);
    }
   
   
    else if(numberArray[i]<54)
    {
    fptr=fopen("out.dat","a");
    sprintf(ch,"%d F",numberArray[i]);
   fprintf(fptr,"%s",ch);
    fclose(fptr);
    }
   
   
    }
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