Write a script to calculate the average score andassign a letter grade for each
ID: 3612695 • Letter: W
Question
Write a script to calculate the average score andassign a letter grade for each student, also compute the averagescore for every test (the source data is in the file“grades”). Output all students’ name, scores, andgrades in descending order of the average score. Note: please savethe output to the file “finalgrades”.
Contents of source data file(grades):
Peter:90:80:70
Alice:79:89:69
David:99:79:89
The final letter grade will be determinedbased on the following criteria:
A: 90 and above; B: 80 thru 89; C: 70 thru 79; D: 60thru 69; E; 50 thru 59; F: <50.
Output (finalgrades)
Explanation / Answer
BEGIN{printf “Name Test1 Test2 Test3 Average Grade”} { average=($2+$3+$4)/3; grade=’F’; if(average<50) grade=’E’; if(average<60) grade=’D’; if(average<70) grade=’C’; if(average<80) grade=’B’; if(average<90) grade=’A’; if(average<100) printf(“%8s%8d%8d%8d%8d%8d ”,$1,$2,$3,$4,average,grade); n+=1;t1+=$1;t2+=$2;t3+=$3; END {printf("%-8s%-8d%-8d%-8d% ","Average",t1/n, t2/n, t3/n} } ITS HELPFUL TO YOU........... } ITS HELPFUL TO YOU...........
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.