Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE C LANGUAGE /* The following is a main program designed to read scores and id numbers from a file, then find the average score,

USE C LANGUAGE /* The following is a main program designed to read scores and id numbers from a file, then find the average score, and assign each student a grade using the following scheme: Each score > average + 20 gets an A Each score between average + 10 and average + 20 gets a B Each score between average - 10 and average + 10 gets a C Each score between average - 20 and average - 10 gets a D Each score < average - 20 gets an F. The main program is coplete. The various subroutines are written as stubs, short functions with just enough content to let them compile. ONE BY ONE, convert each subroutine from a stub to a working module. I will provide a data file named scores.dat which you will use to test your code. */ #include #include #define MAXNUM 100 int getScores(FILE* file, double scores[], int idnums[], int max); double findAverage(double s[], int num); void assignGrades(double s[], char g[], int num, double average); void printSummary(double s[], int ids[], char g[], int numScores, double average); void main(void) { char filename[] = "scores.dat"; FILE *input; double scores[MAXNUM]; int ids[MAXNUM]; char grades[MAXNUM]; int numScores; double average; input = fopen(filename, "r"); if (input == NULL) { printf("Unable to open %s", filename); exit(1); } numScores = getScores(input, scores, ids, MAXNUM); average = findAverage(scores, numScores); assignGrades(scores, grades, numScores, average); printSummary(scores, ids, grades, numScores, average); } int getScores(FILE* file, double scores[], int idnums[], int max) { //for now this is a stub. re-write it so that it reads //scores and id numbers from a file in which each line contains //a score (double) and an id number (int) //fill the arrays scores[] and idnums[] with the data read. Keep //reading until you have read the entire file. Return the number of //scores read as the value of the function. double s; int i, n; int count = 0; n = fscanf(file, "%d %lf", &i, &s); while (n == 2) { printf("%d %f ", i, s); count++; n = fscanf(file, "%d %lf", &i, &s); } printf("You successfully called getScores. "); return count; } double findAverage(double s[], int num) { //Another stub. Re-write this so that it finds the average of the //doubles stored in the first num locations of s[], and returns //that average printf("You successfully called findAverage. "); return 50.0; } void assignGrades(double s[], char g[], int num, double average) { //Yet another stub. Re-write it so that it fills the array g[] with //grades using the rules defined at the start of this page printf("You successfully called assignGrades. "); } void printSummary(double s[], int ids[], char g[], int numScores, double average) { //The last stub. Re write it so that it prints a table. The first //column should be id numbers. The second column should be the corresponding //scores. The third column the amount by which the score differs from the //average. The final column should be the corresponding letter grade. printf("You successfully called printSummary. "); }

Data file

9383 8.86 2777 69.15 7793 83.35 5386 4.92 6649 14.21 2362 0.27 8690 0.59 7763 39.26 540 34.26 9172 57.36 5211 53.68 2567 64.29 5782 15.30 2862 51.23 4067 31.35 3929 98.02 4022 30.58 3069 81.67 1393 84.56 5011 80.42 6229 73.73 4421 49.19 3784 85.37 5198 43.24 8315 43.70 6413 35.26 6091 89.80 9956 18.73 6862 91.70 6996 72.81

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions