-
(Turnin name: grades) Write an awk script called grades.awk that processes a data file similar to the one below and computes averages.
Name:Exam 1:Exam 2:Exam 3 Nina Roth:89:92:87 Tabitha Peterson:98:87:95 Aileen Geving:88:93:95 Becca Hamilton:87:93:95 Cory Christensen:91:95:92
The number of exams will be 3 but the number of students may be different. The output will look (exactly) like this:
Name Exam 1 Exam 2 Exam 3 Average ==================== ========== ========== ========== ========== Nina Roth 89 92 87 89.3 Tabitha Peterson 98 87 95 93.3 Aileen Geving 88 93 95 92.0 Becca Hamilton 87 93 95 91.7 Cory Christensen 91 95 92 62.7 ==================== ========== ========== ========== ========== Average 90 92 92 85.8
Make sure the column widths are correct. Note: You need to set the field separator. Turnin will not do it when it runs awk, so you need to do it in the program. This can be done like this:
FS = ":";
in an action with patternBEGIN
. -
(Turnin name: hist) Write an awk program called hist.awk that reads a file of numbers and prints a histogram of occurrences. For the input shown below:
1 4 5 0 2 4 6 8 1 3 2 4 6 7 2 3 3 4 4
the output will be
0: 1 *** 1: 2 ****** 2: 3 ******** 3: 3 ******** 4: 5 ************** 5: 1 *** 6: 2 ****** 7: 1 *** 8: 1 ***
The first column contains the numbers from the file. The second contains the number of times that number occurred. The graph shows the percentage of the total, scaled to 50, so 50 asterisks indicates 100%, 25 asterisks indicates 50%, and so on.