UNB/ CS/ David Bremner/ teaching/ cs2613/ tests/ CS2613 Midterm

The midterm, worth 20% of your mark, was held in the lab (GC112) at 11:30AM on October 25, 2018.

Exam format and reference

The exam will be "open book" with the following list of permitted reference material

Questions and what to hand in

Topics

The test will cover all the material from labs 2-13, and assignments 1-3.

Time will not allow for questions on every topic covered, but you should be prepared for questions on of the covered topics

A non-exhaustive list of Racket and JavaScript topics is given below.

Racket

JavaScript

Sample questions

Racket

Write a racket function list->hash that, given a list, returns a hash table which maps the number i to the list element in ith position (starting from position 1). For full marks, your function should - pass the following tests, - be tail recursive, and - not use mutation (no functions ending in '!').

(module+ test
  (require rackunit)
  (define hash-table (list->hash (list "a" "b" "c") (hash) 1))
  (check-equal? (hash-ref hash-table 1) "a")
  (check-equal? (hash-ref hash-table 2) "b")
  (check-equal? (hash-ref hash-table 3) "c"))

JavaScript

In this question, the Expr JavaScript class represents simple expressions using multiplication and addition, e.g.~(6*9)+(3*4). Write the eval method for Expr. Your method should compute the value of the expression (a number), and should pass the following jasmine tests

let Expr=require("../expr.js").Expr;

describe("expr",
         function() {
             let six_plus_nine = new Expr('+', 6, 9);
             let six_times_nine = new Expr('*', 6, 9);
             it("addition",
                function() {
                    expect(six_plus_nine.eval()).toBe(15);
                });
             it("multiplication",
                function() {
                    expect(six_times_nine.eval()).toBe(54);
                });
             it("compound",
                function() {
                    expect(new Expr('+', six_times_nine,
                                    six_plus_nine).eval()).toBe(69);
                });});