Line 52: |
Line 52: |
| x .91 | | x .91 |
| / .86 | | / .86 |
| + | </pre> |
| | | |
| + | '''''Grader.awk:''''' |
| + | <pre> |
| + | #!/usr/bin/awk |
| + | |
| + | # grades -- average student grades and determine |
| + | # letter grade as well as class averages |
| + | # at the command line run: awk -f grader.awk grades.dat |
| + | |
| + | BEGIN { OFS = "\t"; "date +%H:%M:%S" | getline current_time |
| + | close("date +%H:%M:%S") |
| + | print "Report printed on " current_time |
| + | } |
| + | |
| + | # action applied to all input lines |
| + | { |
| + | # add up the grades |
| + | total = 0 |
| + | for (i = 3; i <= NF; ++i) # i=3 skips first 2 fields - last name, first name |
| + | total+=$i |
| + | |
| + | # calculate average |
| + | avg = total / (NF - 2) |
| + | |
| + | # assign student's average to element of array |
| + | class_avg[NR] = avg |
| + | |
| + | # determine letter grade |
| + | if (avg >= 90) grade="A" |
| + | else if (avg >= 80) grade="B" |
| + | else if (avg >= 70) grade="C" |
| + | else if (avg >= 60) grade="D" |
| + | else grade="F" |
| + | |
| + | # increment counter for letter grade array |
| + | ++class_grade[grade] |
| + | |
| + | # print student first name, last name, average interger value, and letter grade |
| + | print $2 " " $1, int(avg), grade#, NF, NF |
| + | } |
| + | |
| + | # print out class statistics |
| + | END { |
| + | # calculate class average |
| + | for (x = 1; x <= NR; x++) |
| + | class_avg_total += class_avg[x] |
| + | class_average = class_avg_total / NR |
| + | |
| + | # determine how many above/below average |
| + | for (x = 1; x <= NR; x++) |
| + | if (class_avg[x] >= class_average) |
| + | ++above_average |
| + | else |
| + | ++below_average |
| + | |
| + | # print results |
| + | print "" |
| + | print "Class Average: ", class_average |
| + | print "At or Above Average: ", above_average |
| + | print "Below Average: ", below_average |
| + | |
| + | # print number of students per letter grade |
| + | for (letter_grade in class_grade) |
| + | print letter_grade ":", class_grade[letter_grade] |
| + | |
| + | } |
| </pre> | | </pre> |
| | | |
| ==Helpful stuff== | | ==Helpful stuff== |