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

NEED THIS PROGRAM IN C++ OR C Grade Point Average Calculator Objective: Write a

ID: 3671824 • Letter: N

Question

NEED THIS PROGRAM IN C++ OR C

Grade Point Average Calculator

Objective:

Write a program that reads from a file a list of course names, letter grades for each course and number of credits each course is worth. The program will read each course name, grade earned and number of credits from the file and print out the course name, grade earned and number of credits for each course to the screen. After the program has read in all of the courses, grades earned and credits, the program should calculate the grade point average based on all of the courses read in by the program.

Notes:

Students who receive an “F” grade earn zero credits for the course but the grade is still used as part of the GPA calculation

When displaying the GPA, only display up to two decimal points

Sample Input File: A data file named grades.txt will be attached as part of the assignment. It will contain sample course names, grades earned and number of credits attempted. Your program should read this file in as input. Make sure you put this file in the same directory as your project. Below is a sample of the input file.

Jane Doe

Chemistry A 4.0

Calculus B 4.0

History C 3.0

Gym A 1.0

English A 3.0

Computing GPA: Grade point average is calculated by multiplying the number of credits earned for a course by the point equivalent of the letter grade for that course. That product is computed for each course and summed together as the total number of points earned. That total is then divided by the number of total credits attempted to give you the GPA. Below is a example of how GPA is calculated.

Chemistry B 4: 3 points for grade x 4 credits = 12

Math A 3: 4 points for grade x 3 credits = 12

Gym C 1: 2 points for grade x 1 credit = 2

=====================================

This is a total of 26points. The 26 points is then divided by total number of credits to get GPA.

GPA = 26/8 = 3.25

Letter Grade-To-Points Scale: The letter grade to points scaled is displayed below:

A = 4 points

B = 3 points

C = 2 points

D = 1 point

F = 0 points

Sample Results: The program’s output should look something like the sample output below. You can be creative with your output layout so long as all of the important information is captured.

Sample Output:

Jane Doe’s Grade Point Average Calculator

Course Name                   Grade Earned                    Number of Credits Earned

Chemistry                          A                                          4.0

Calculus                              B                                           4.0

History                                C                                           3.0

Gym                                     A                                           1.0

English                                A                                           3.0

The GPA for this student is:           3.3 and credits earned are:           15.

Explanation / Answer

int main()
{
   int dummy;

   FILE* spGrades;

   float credits;
   float GPA;
   char name;
   char grade;
   char course[25];
   char string[60];

   float count = 0;
   float Points = 0;
   float totalPoints = 0;
   float totalCredits = 0;
   float totalCreditsEarned = 0;

   printf("This program will read and print the students name, the course names, ");
   printf("the letter grades of that course and the number of credits each course is worth.");
   printf("It will then calculate the GPA of the courses.");

   spGrades = fopen("grades.txt", "r");
   if (!spGrades)
   {
       printf(" Could not open file grades.txt  ");
       exit(101);
   }

   fgets(string, 60, spGrades);
   printf(" Student name: %s ", string);
   printf("     |Course Name| |Grade Earned| |Credits Hours| ");

   while (fscanf(spGrades, "%s %c %f ", &course, &grade, &credits) != EOF)
   {
       printf("%15s      %3c     %12.1f ", course, grade, credits);
      
       if (grade == 'A'){
           Points = 4.0;
       }
       else if (grade == 'B'){
           Points = 3.0;
       }
       else if (grade == 'C'){
           Points = 2.0;
       }
       else if (grade == 'D'){
           Points = 1.0;
       }
       else if (grade == 'F'){
           Points = 0.0;
       }

       totalCredits = credits + credits + credits + credits + credits;
       totalPoints = credits*Points;
       totalCreditsEarned += totalPoints;
       count++;
   }

   GPA = totalCreditsEarned / totalCredits;

       fclose(spGrades);

  
   printf("---------------------------------------------------------------------- ");
   printf(" The Total Credits earned by this student are: %.1f ", totalCreditsEarned);
   printf(" The GPA for this Student is: %.2f ", GPA);
   printf("---------------------------------------------------------------------- ");


   printf(" The program has finished. Press enter to exit. ");
   scanf_s("%d", &dummy);
   return 0;
}