Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program only, will RATE: I've finished everything except for the bolded part, the final result should look like something that I put in bold

C program only, will RATE: I've finished everything except for the bolded part, the final result should look like something that I put in bold and italic.

Compile and run the program found in grader.c. This program is intended to read test scores and print out a grade. Note that it currently assigns all students a grade of '?', not what we ultimately want. Also note that this program is again undocumented! and not well organized, even for such a small program. Your first task is to break this program up into three files, one for the driver, and one for the function with it's associated .h file. Your second task to add comments to your files to properly document the program showing the algorithm (with comments showing the meaning of the steps, NOT describing the C code), and properly documenting the function and its prototype. Compile this program using make to verify it compiles and runs at this point.

Update the body of the assign_grade() function so that it returns an appropriate letter grade: 'A' for a score between 90 and 100, 'B' for a score between 80 and 89, 'C' for a score between 70 and 79, 'D' for a score between 60 and 69, and an 'F' for a score between 0 and 59. An out-of-range score (less than 0 or over 100) should result in a '?' being returned for the grade. Here's the sample output for the data in mygrader.dat (also located in the ee160 folder):

 95: A 85: B 80: B 75: C 70: C 68: D 50: F 104: ? -10: ? 

Hint: There are two ways to do this: one using an else-if, the other as a set of simple if statements, each having a return statement in the then-part of the statement.Now extend the mygrader program to print an error message for bad grades, rather than just a question mark.

 95: A 85: B 80: B 75: C 70: C 68: D 50: F 104: illegal score -10: illegal score 

Hint: Think about where you should put the change; in main() or the function assign_grade().Copy your files for this program to new file names and extend this program to read in the grading scale. That is the first 4 input values are taken as the minimum grade for an A, for a B, for a C, and for a D. Here's an example using the traditional grading scale with input from the file mygrader2.dat (also available on wiliki):

 95: A 85: B 80: B 75: C 70: C 68: D 50: F 104: illegal score -10: illegal score 

Hint: It helps to change the assign_grade() function to take the different items of the grading scale as parameters.

In addition, extend the mygrader2 program to verify that the grading scale is reasonable. That is, the minimum score for an A must be larger than the minimum score for a B, and the minimum score for a B must be larger than the minimum score for a C, and so on. The minimum score for an A must also be no larger than 100 and the minimum score for a D must be no smaller than a 0. If it is not, you print a message before reading and processing any of the scores. Here is an example of an illegal grading scale and the resulting program output.

90 95 70 60 invalid grading scale 

Hint: It helps to write a function that determines whether the grading scale is valid.Extend the program to print the total number of students who pass or fail, where passing is a grade of 'C' or better and failing is a 'D' or 'F'. This output goes at the end.

 95: A 85: B 80: B 75: C 70: C 68: D 50: F 104: illegal score -10: illegal score Passing scores: 5 Failing scores: 2 Illegal scores: 2

Below is the code of my file:

grader.c:

#include

#include"grader.h"

char assign_grade(int score)

{

if (score == 90 || score == 80 || score == 70 || score == 60)

{

return 1;

}

if (score > 90 && score <= 100 )

{

return 'A';

}

else if (score >80 && score<90)

{

return 'B';

}

else if (score >70 && score<80)

{

return 'C';

}

else if (score >60 && score<70)

{

return 'D';

}

else if (score >=0 && score<60)

{

return 'F';

}

else if (score <0 || score>100)

{

return 0;

}

}

grader.h

char assign_grade(int score);

driver.c

#include

#include"grader.h"

int main()

{

/* declare variables */

FILE *in;

int score;

char grade;

int pass;

int fail;

int illegal;

/* call the .dat file */

in = fopen("mygrader2.dat","r");

/* initialize variables */

pass = fail = illegal = 0;

/* scan in the data from .dat file, print out grade and calculate the total numbers of passing/failing/ illegal grade */

while(fscanf(in,"%d", &score) == 1)

{

printf("%d: ", score);

grade = assign_grade(score);

if (grade == 0)

{

illegal = illegal +1;

printf("illegal score");

}

else if (grade == 1)

{

printf("invalid grading scale");

}

else if (grade == 'A' || grade == 'B' || grade == 'C')

{

pass = pass +1;

}

else if (grade == 'D' || grade == 'F')

{

fail = fail +1;

}

printf("%c ", grade);

}

/* print out the total numbers of passing/failing/illegal grade */

printf("Passing score: %d ",pass);

printf("Failing score: %d ",fail);

printf("Illegal score: %d ",illegal);

fclose(in);

return(0);

}

grader2.dat:

mygrader2.dat

 
90 80 70 60 95 85 80 75 70 68 50 104 -10

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

Students also viewed these Databases questions