Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the grade book program from Unit 3 (see my program below) to use a custom struct to hold the student's ID number and the

Modify the grade book program from Unit 3 (see my program below) to use a custom struct to hold the student's ID number and the percentage score for each item in the grade book. The program should accept the entry of ID numbers and percentage grades (0100) until the user signals that he or she is done entering grades. The program should then print out the ID numbers and grades entered by the user, sorted by ID number. Again, be sure to format the code properly and provide comments in the C code. Be sure to include comments.

#include #include #include #include

float average(int*arr, int count){ /* get the Average among the elements */ int i; /* local control variable */ float sum = 0.0; /* declares sum */ for(i=0;i

return max;

}

int lowest(int*arr, int count){ /* get the lowest factor among all the elements */ int min = INT_MAX; int i = 0; /* declares variable */ for (i=0;iarr[i]){ min = arr[i];

} }

return min;

}

char printAvgGrade(float avg){ if (avg>=0 &&avg<=100){ /* conditions for the grade*/ if (avg>=0 &&avg<60) return 'F'; else if (avg>=60 &&avg<70) return 'D'; else if (avg>=70 &&avg<80) return 'C'; else if (avg>=80 &&avg<=90) return 'B'; else if (avg>=90 &&avg<=100) return 'A'; }

else { printf(" Invalid numeric grade!");

}

return;

}

char printGrade(int score){ if (score>=0&&score<=100){ /* condition for the grade */ if (score>=0&&score<60) return 'F'; else if (score>=60 &&score<70) return 'D'; else if (score>=70 &&score<80) return 'C'; else if (score>=80 &&score<90) return 'B'; else if (score>=90 &&score<=100) return 'A'; }

else { printf(" Invalid numeric grade!");

}

return;

}

int main() {

char choice; /* choice of user *//* array of scores */ int *gradeScoreArray;/* array of scores */ int gradeScore; /*grade scores defined as an integer */ int count=0, i, high, low; float avg; char LetterGrade;/* letter grade defined as a character */

gradeScoreArray = (int *) calloc(50, sizeof(int)); /* allocated space in heap*/

do{ /* Tells the program to do the loop for the case at least one time */ printf("-------------------Please enter your choice--------------- To add grade score(a) To quit(q) "); /* Ask user to select choice (a) or (q) for quit */ scanf(" %c",&choice); /* getting user input */ switch(choice){ i = 0; case 'a': printf("Please enter the scores between 0 to 100 "); /* Ask user to enter grade scores */ scanf(" %d",&gradeScore); /* getting user input */ gradeScoreArray[count]=gradeScore;/* adding the scores to array */ count++; break;

case 'q': printf("Grades entered by the user "); /* prints grade entered by user */

for (i = 0;i

printf(" %d", gradeScoreArray[i]); /* print grades */

}

avg = average(gradeScoreArray, count); /* getting avg */ low = lowest(gradeScoreArray, count); /* getting lowest grade */ high = highest(gradeScoreArray, count); /* getting highest grade */ printf(" Average( %f) grade: %c ", avg, printAvgGrade(avg)); /* printing avg grade */ printf("Highest( %d) grade: %c ", high, printGrade(high)); /* printing highest grade */ printf("Lowest( %d) grade: %c ", low, printGrade(low)); /* printing lowest grade */

break;

default:

printf("Invalid choice"); } } while (choice !='q'); /* exits loop for q */

free(gradeScoreArray);

getchar(); /*pause window */

getch();

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions