diff --git a/Summer-2024/CS-3424/Quizzes/Quiz-5/Assignment.typ b/Summer-2024/CS-3424/Quizzes/Quiz-5/Assignment.typ new file mode 100644 index 0000000..8b69fd2 --- /dev/null +++ b/Summer-2024/CS-3424/Quizzes/Quiz-5/Assignment.typ @@ -0,0 +1,141 @@ +#set text(font: "FreeSans") +#set page(margin: 1cm) + +#show link: item => [ + #text(blue)[#item] +] + +#show raw: set text(font: "Fira Code") +#show raw.where(block: false): item => { + box(inset: (x: 1pt))[#box( + stroke: luma(40%) + .1pt, + fill: luma(97%), + outset: (y: 3pt, x: 1pt), + radius: 2pt, + )[#item]] +} +#show raw.where(block: true): item => { + set par(leading: .5em, justify: false) + align(center)[ + #block( + outset: 0pt, + stroke: luma(40%) + .5pt, + fill: luma(97%), + radius: 3pt, + )[ + #align(left)[#rect( + radius: ( + top-left: 3pt, + bottom-right: 3pt, + ), + inset: .3em, + stroke: ( + bottom: luma(40%) + .5pt, + right: luma(40%) + .5pt, + ), + fill: blue.transparentize(95%), + )[#text(fill: blue)[#item.lang]]] + #v(-1em) + #box(inset: 4pt)[#item] + ]] +} + +#let answer(ans) = { + set text(size: .95em, style: "italic", fill: rgb(64, 90, 95)) + block( + inset: 4pt, + stroke: blue + .5pt, + fill: rgb(0, 149, 255, 5%), + radius: 3pt, + )[#for child in ans.fields().children { + if child.func() == raw { + text(fill: black)[#child] + } else { + child + } + } + ] +} + +#align(center)[#text(size: 1.3em)[= CS 3424 Quiz - Week 8]] +#align(center)[ + #("Price Hiller", "zfp106", "Quiz 5", "CS 3424").join(" ⋄ ") + #v(-.5em) + #text(size: 0.8em)[#block( + inset: 4pt, + radius: 1pt, + stroke: luma(40%) + .2pt, + width: 40%, + fill: luma(97%), + )[#par(leading: .4em)[If you are interested in viewing the source code of this document, you can do so + by clicking + #link( + "https://git.orion-technologies.io/Price/college/src/branch/Development/Summer-2024/CS-3424/Quizzes/Quiz-5/Assignment.typ", + "here.", + )]]] + #v(-.5em) + #line(length: 100%, stroke: (dash: "densely-dotted")) + #v(-.5em) +] + + +1. Given the list of grades, `grades.txt`, for the input file below, create an `awk` script, `quiz.awk`, which prints only the student’s name (first then last), grade, and assignment for the section passed as an argument. At the end, print the average grade and the number of failing grades (<= 60) for the specified section. Each line in the input file contains the following fields in this order: *lastName, firstName, section, assignment, grade*. Assume names do not have spaces. Print the output to a file called `gradesFiltered.txt`. + ```sample + Adams John 2 1 30 + Addams Gomez 3 3 80 + Allen Tim 2 1 90 + Ball Lucille 3 2 76 + Buscemi Steve 3 1 80 + Busey Gary 1 3 43 + Cage Nicolas 2 5 110 + ``` + + #answer[ + The script below assumes it will be run via `awk -f -v 'section=3' ./grades.txt`. + ```awk + BEGIN { + if (!section) { + print "`section` variable was not passed, pass it via `-v 'section='`" > "/dev/stderr" + exit 1 + } + students_in_section=0 + number_failing_grades=0 + } + { + student_last_name=$1 + student_first_name=$2 + student_section=$3 + student_assignment=$4 + student_grade=$5 + if (student_section == section) { + print student_first_name,student_last_name,student_grade,student_assignment > "gradesFiltered.txt" + students_in_section += 1 + sum += student_grade + if (student_grade <= 60) { + number_failing_grades+=1 + } + } + } + END { + if (students_in_section > 0) { + print "Average grade: " sum / students_in_section > "gradesFiltered.txt" + print "Number of failing grades: " number_failing_grades > "gradesFiltered.txt" + } else { + print "No students found in section: " section > "/dev/stderr" + exit 1 + } + } + ``` + + #figure( + box(clip: true, radius: 4pt)[#image( + "assets/awk-script-in-action.png", + height: 55%, + fit: "contain", + alt: "", + )], + caption: [ + Image of the provided ```bash awk``` script being ran. + ], + ) + ] diff --git a/Summer-2024/CS-3424/Quizzes/Quiz-5/assets/awk-script-in-action.png b/Summer-2024/CS-3424/Quizzes/Quiz-5/assets/awk-script-in-action.png new file mode 100644 index 0000000..db5ded2 Binary files /dev/null and b/Summer-2024/CS-3424/Quizzes/Quiz-5/assets/awk-script-in-action.png differ