Professor James asked you to write a letter grade program for him. The program s
ID: 3669181 • Letter: P
Question
Professor James asked you to write a letter grade program for him. The program should ask for score and display the appropriate letter Grade base on the following grading policy. Use WHILE statement to repeat the program for 5 Students with grade of (90, 72,89,56, 62).
If Grade >= 90 print “A” and “excellent”
Grade >= 80 print “B” and “very Good”
Grade >= 70 print “C” and “Good”
Grade >= 60 print “D” and “passed”
Below 60 is “F”
Submit the following :
1) Algorithem 25
2) Source code 40
3) output 10
Explanation / Answer
Hi Below i added the code for your requirement, Please excecute with the code given.
#include <stdio.h>
#define MAX_ENTRIES 50
int main (void)
{
/*I need to set my array to allow for up to 50 students and their
test scores and set my "count" variable as well as the i. There will
also need to be a variable for average test score, highest score,
and the corresponding grade values. */
int student_ID[MAX_ENTRIES]; //student ID counter
int test_score[MAX_ENTRIES]; //test score counter
int above_ave; /*number of test scores above the
average*/
int grade_count[MAX_ENTRIES]; //total number of grades
int count = 0; /*number of elements in ID, score
and grade arrays*/
int sum; //sum of all test scores
int i; //loop counter
int high_score; //the highest test score
int high_stud_ID; //student_ID with highest score
float ave_score; //average test score
int A = 0, B = 0, C = 0, D = 0, F = 0;
char char_val; //A, B, C, D, F
char grade[5]; //grade counter
//Start to fill my Array with Student IDs and test scores
while (count < MAX_ENTRIES && student_ID[count] != 0)
{
printf("Enter a student's ID: ");
scanf("%i", &student_ID[count]);
if ( student_ID[count] == 0 )
break;
printf("Enter the student's test score: ");
scanf("%i", &test_score[count]);
++count;
}
//Adjust count for ACTUAL number of students
//--count
//Set letter grade values to the "test_score" variable
for ( i=0; i<=count; ++i )
{
if ( test_score[i] >= 90 )
grade_count[i] = 'A';
else if ( test_score[i] >= 80 )
grade_count[i] = 'B';
else if ( test_score[i] >= 70 )
grade_count[i] = 'C';
else if ( test_score[i] >= 60 )
grade_count[i] = 'D';
else if (test_score[i] <= 59 )
grade_count[i] = 'F';
}
for ( i = 0; i < count; ++i )
{
if ( test_score[i] >= 90 )
++A;
else if (test_score[i] >= 80 )
++B;
else if ( test_score[i] >= 70 )
++C;
else if ( test_score[i] >= 60 )
++D;
else if ( test_score[i] >= 50 )
++F;
}
sum = 0;
sum += test_score[count];
//This will set up my student_ID : test_score : grade table
printf (" Student ID Test Score Letter Grade ");
printf("---------- ---------- ------------ ");
for (i = 0; i<count; ++i)
printf("%i %i %c ", student_ID[i], test_score[i], grade[i]);
//check for divide by zero
if ( count == 0 )
printf("Division by zero not allowed ");
else
ave_score = (float)sum / count;
for(i = 1; i < count; ++i)
{
if (test_score[i] > ave_score)
++above_ave;
}
//Set up the highest test score
high_score = test_score[0];
for(i = 1; i <= count; ++i)
{
if( test_score[i] > high_score )
high_score = test_score[i];
if ( high_score >= 90 )
char_val = 'A';
else if ( high_score >= 80 )
char_val = 'B';
else if
( high_score >= 70 )
char_val = 'C';
else if
( high_score >= 60 )
char_val = 'D';
else if
(high_score <= 59 )
char_val = 'F';
high_stud_ID = test_score[i];
}
/*Print my test score average, number of grades above average, and
number of each letter grade */
printf("The average of all the test scores = %f ", ave_score);
printf("The number of test scores above the average is %i ", above_ave);
printf("Student %i received the highest score %i - %c ", student_ID[i], high_score, grade[i]);
printf ("The number of As is: %2i ", A);
printf ("The number of Bs is: %2i ", B);
printf ("The number of Cs is: %2i ", C);
printf ("The number of Ds is: %2i ", D);
printf ("The number of Fs is: %2i ", F);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.