diff --git a/examples/exam_example.typ b/examples/exam_example.typ index bf5d974..b56c05b 100644 --- a/examples/exam_example.typ +++ b/examples/exam_example.typ @@ -432,15 +432,6 @@ Use the code block to answer the following questions: [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T ) -#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, - [```java LinkedList``` utilizes nodes and next pointers to store information], // T - [```java ArrayList``` is always faster than ```java LinkedList```], // F - [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F - [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T - [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T -) - - Fill in some code below: #code-block( @@ -454,3 +445,51 @@ Fill in some code below: ) ```, width: 100%) + + + +#pagebreak() +#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, + [```java LinkedList``` utilizes nodes and next pointers to store information], // T + [```java ArrayList``` is always faster than ```java LinkedList```], // F + [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F + [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T + [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T +) + + + + +#e.question-block([Use the block to answer the following questions:], + () => e.short-answer( + "What is the time complexity of the method shown above?", + lines: 2, + points: 2 + ), + () => e.multiple-choice( + "Which data structure would optimize this code?", + points: 1, + cols: 2, + [Array List], + [Hash Map], + [Linked List], + [Binary Tree] + ) +) + +#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, + [```java LinkedList``` utilizes nodes and next pointers to store information], // T + [```java ArrayList``` is always faster than ```java LinkedList```], // F + [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F + [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T + [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T +) +#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, + [```java LinkedList``` utilizes nodes and next pointers to store information], // T + [```java ArrayList``` is always faster than ```java LinkedList```], // F + [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F + [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T + [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T +) + +#e.question("Please write your favorite algorithm below:", points: 4) \ No newline at end of file diff --git a/src/exams.typ b/src/exams.typ index 92f6597..fa25516 100644 --- a/src/exams.typ +++ b/src/exams.typ @@ -106,6 +106,10 @@ "num-qs", 1 ) +#let cur-sub-question = counter( + "sub-question-n" +) + /// question: Create a generic question /// - body (content, str): Question Body @@ -121,15 +125,31 @@ message: "Expected points to be int, but received" + str(type(points)) ) - cur-question.update(n => n + 1) total-points.update(p => p + points) - let qnum = cur-question.get() - + let q-num = cur-question.get() + + // counters return an array, despite only having 1 value + // this relies that is set in question-block + let sub-val = cur-sub-question.get().at(0) + let has-sub = sub-val != 0 + + let sub-label = if has-sub { + [#cur-sub-question.display("A")] + } else { + none + } + + // only update the q num if the question has NO sub questions + if not has-sub { + cur-question.update(n => n + 1) + } + block(width: 100%, breakable: true, inset: (bottom: 0.5em))[ #grid( columns: (20pt, 1fr), column-gutter: 8pt, - text(weight: "bold")[#qnum.], + // TIL ~ is a non-breaking space + text(weight: "bold")[#q-num~#sub-label.], [#body #h(5pt) (#points pts)] ) ] @@ -499,3 +519,21 @@ } + +#let question-block(q-body, ..questions) = { + // basically just a wrapper, that manages some state for the question() function + cur-sub-question.update(1) + + for q in questions.pos() { + q() + cur-sub-question.step() + } + + // disable sub-question state + // and keep the cur-question moving + cur-question.update(n => n + 1) + cur-sub-question.update(0) + + +} +