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

Write a C program that does the following: Read the students information from in

ID: 3788122 • Letter: W

Question

Write a C program that does the following: Read the students information from input file as follows. First Name Last Name Test 1 Test 2 Final Exam 1 First Name2 Last Name2 Test 1 Test 2 Final Exam First Name3 Last Name Test 1 Test 2 Final Exam Find the Course score for each student by allocating 35% for Max(Test1, Test2), 25% for Min (Test1, Test2) and 40% for the Final Exam. Round the course scores up. Find the letter grade for each student using the following criteria: [90-100] A [80-89] B [70-79] C [60-69] D

Explanation / Answer

C code

#include<stdio.h>
#include<math.h>
char grad(double a) // function go get grade
{
   if(a<=100 && a>=90) return 'A';
   else if(a<90 && a>=80) return 'B';
   else if(a<80 && a>=70) return 'C';
   else if(a<70 && a>=60) return 'D';
   else return 'F';
}
int main()
{
   char inFile[50],outFile[50],FirstName[100][50],SecondName[100][50];
   float Test1[100],Test2[100],Final[100],Course_Score[100],temp;
   int k = 1,j,i,position[100],tem;
   FILE *inf,*outf;
   printf("Enter the name of input file :");
   scanf("%s",inFile);
   inf = fopen(inFile,"r"); // opening the file to read data
   while(k)
   {
     j = k-1;
     fscanf(inf,"%s %s %f %f %f",FirstName[j],SecondName[j],&Test1[j],&Test2[j],&Final[j]); // reading data
     Course_Score[j] = 40.0*Final[j]/100.0; // finding the score
     if(Test1[j]>Test2[j]) Course_Score[j] += (35.0*Test1[j]+25.0*Test2[j])/100.0;
     else Course_Score[j] = ceil(Course_Score[j]+(35.0*Test2[j]+25.0*Test1[j])/100.0);
     position[j] = j;
     k+=1;
     if(feof(inf)) k=0;
   }
   fclose(inf);
   for(k = 0; k<j;k++) // loops for buble sort
     for(i = 0;i<j-1;i++)
         if(Course_Score[i] > Course_Score[i+1])
         {
              temp = Course_Score[i+1];
              Course_Score[i+1] = Course_Score[i];
              Course_Score[i] = temp;
              tem = position[i+1];
              position[i+1] = position[i];
              position[i] = tem;
          }
   printf("Enter the name of output file :");
   scanf("%s",outFile);
   outf = fopen(outFile,"w"); // open file to write the data
   for(k = 0; k<j;k++)
   {
       fprintf(outf,"%s %s %f %c ",FirstName[position[k]],SecondName[position[k]],Course_Score[k],grad(Course_Score[k]));
   }
   return 0;
}


   Testing the code

list.txt

dfadsf vs 100 100 100
dfsd fdg 90 60 100
tynb gthy 4 16 50
fghg jjy 100 80 70
fhg hh 6 6 10
hghht ty 10 90 70

running the program

$ gcc StudentInfo.c -lm
$ ./a.out
Enter the name of input file :list.txt
Enter the name of output file :result.txt

result.txt

fhg hh 8.000000 F
tynb gthy 27.000000 F
hghht ty 62.000000 D
fghg jjy 83.000000 B
dfsd fdg 86.500000 B
dfadsf vs 100.000000 A

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