Final Exam Grading

From CSE190M-Admin

Jump to: navigation, search

Contents

[edit] Question 1

window.onload = function() {
    $("eat").onclick = eatClick;
};

function eatClick() {
    var name = $("foodname").value.toLowerCase();
    var group = $("foodgroup").value;
    var elements = $$("img.food");
    for (var i = 0; i < elements.length; i++) {
        if (elements[i].hasClassName(group)
                && elements[i].alt.toLowerCase() == name) {
            elements[i].remove();
        }
    }
}

25 points total

  • 5 window onload
    • 3 window.onload handler function declared properly
    • 2 onclick handler attached to 'eat' button properly
  • 20 eat onclick handler
    • 2 grabs food name and group values correctly (-1 for a tiny mistake such as saying .textContent instead of .value)
    • 10 selecting the right elements to examine
      • 2 selects only img elements
      • 4 selects only with class 'food' (-2 if they test == on .className)
      • 4 selects only from proper food group (-2 if they test == on .className)
        • -5 if they sequentially test for each of these things, basically doing || vs. &&
    • 8 determining whether to remove a given image
      • 3 compares alt text to food name properly
      • 2 case sensitivity (1 for an attempt such as .equalsIgnoreCase, which doesn't exist in JS)
      • 3 removes element from the page properly
        • -1 for assuming page content such as using $$("p")[0]

[edit] Question 2 (Ajax/XML)

window.onload = function() {
    new Ajax.Request("personality.php",
        {
            method: "get",
            onSuccess: ajaxSuccess
        }
    );
};

function ajaxSuccess(ajax) {
    var persons = ajax.responseXML.getElementsByTagName("person");
    for (var i = 0; i < persons.length; i++) {
        var name = persons[i].getAttribute("name");
        var type = persons[i].getAttribute("type");
        var answers = persons[i].getElementsByTagName("answers")[0].textContent.toLowerCase();
        var b = 0;
        for (var j = 0; j < answers.length; j++) {
            if (answers[j] == "b") {
                b++;
            }
        }
        
        var li = document.createElement("li");
        li.textContent = name + ": " + type + " (" + b + " Bs)";
        $("output").appendChild(li);
    }
}

25 points total

  • 6 window onload
    • 1 window.onload handler attached properly
    • 2 Ajax request attempt
    • 1 method "get"
    • 2 attaches onSuccess handler properly
  • 19 Ajax onSuccess handler
    • 1 header (including ajax parameter)
    • 8 XML parsing
      • 3 correctly grabs all "person" elements and loops over them (1 attempt, 2 correct)
        • -5 if they only process the first person (person[0])
      • 2 correctly grabs attributes e.g. "name", "type"
      • 3 correctly grabs "answer" tag and the text content inside of it (1 attempt, 2 correct)
    • 6 counts "B"s
      • 2 attempt
      • 3 correct (other than case-sensitivity)
        • such as if they declare their Bs counter in the wrong place, don't reset it, etc.
      • 1 case-sensitivity
    • 4 li added to page
      • 2 creates/adds list item to page
      • 2 correct list item text

[edit] Question 3 (PHP)

<?php
$min = -1;
if (isset($_REQUEST["name"]]) {
    $text = file_get_contents("names.txt");
    $lines = explode("\n", $text);
    foreach ($lines as $line) {
        $tokens = preg_split("/[ ]+/", $line);
        $this_name = array_shift($tokens);
        if (strtolower($this_name) == strtolower($_REQUEST["name"])) {
            foreach ($tokens as $rank) {
                if ($min == -1 || $rank < min) {
                    $min = $rank;
                }
            }
        }
    }
}

header("Content-type: text/plain");
print "$min\n";
?>

25 points total

  • 7 file I/O
    • 1 reads file contents
    • 3 splits by lines properly (explode or preg_split)
    • 3 splits each line into tokens by spaces correctly (explode or preg_split)
  • 11 examining matching lines
    • 3 searches for the matching line correctly (compares name tokens)
      • -2 if it just does a string indexOf test on the entire line looking for the name
    • 1 case sensitivity of name comparisons
    • 1 keeps track of a $min variable for the smallest ranking seen
    • 6 loops over rankings, looking for the smallest one (3 attempt, 3 correct)
      • -2 if they compare against the name as well as the rankings
  • 7 basic stuff, and edge cases
    • 1 ?php ? surrounding tags
    • 1 header content-type
    • 2 prints out minimum value (\n not needed)
    • 1 prints -1 if name parameter is not passed
    • 2 prints -1 if the name is not found in the file (must explicitly check for this; using min() function won't work if $min is initialized to -1)
      • -2 if they print -1 many times, e.g. once for each name that does not match

[edit] Question 4 (SQL)

SELECT DISTINCT t.name, c.name
FROM   teachers t
JOIN   courses c ON c.teacher_id = t.id
JOIN   grades g1 ON g1.course_id = c.id
JOIN   grades g2 ON g2.course_id = c.id
WHERE  g1.student_id <> g2.student_id
AND    g1.grade <= 'C-' AND g2.grade <= 'C-';

SELECT DISTINCT t.name, c.name
FROM   teachers t
JOIN   courses c ON c.teacher_id = t.id
JOIN   grades g1 ON g1.course_id = c.id
JOIN   students s1 ON s1.id = g1.student_id
JOIN   grades g2 ON g2.course_id = c.id
JOIN   students s2 ON s2.id = g2.student_id
WHERE  s1.name < s2.name
AND    g1.grade <= 'C-' AND g2.grade <= 'C-';

25 points total

  • 5 SELECT
    • 2 columns teacher name, course name (probably requires the student to give names to their tables in the query)
    • 3 DISTINCT (no duplicates)
  • 9 FROM/JOIN (choice of tables)
    • 2 one 'teachers' record
    • 3 one 'courses' record
    • 4 two 'grades' records (and 'students' records if needed)
      • -2 for each extra record added unnecessarily if it screws up the query; -0 if it doesn't
  • 11 WHERE/ON (constraints)
    • 2 teacher <-> course by id
    • 3 course <-> two grades by id
    • 3 two grades <-> two students by id (makes sure the two students' ids are different)
    • 3 checks for grades above 'C-' (N for each) (-1 for > instead of <)
    • -2 for each extra incorrect constraint if it screws up the query; -0 if it doesn't