Final Exam Grading 11sp

From CSE190M-Admin

Jump to: navigation, search

Contents

[edit] Exam


[edit] Question 1 (HTML/CSS Tracing)

Final 11sp q1 key.png

20 points total

  • 2 alignment: a/b text is close to right edge of enclosing div
  • 3 background color: overall #b area, and one/two spans (-1 if missing from one span; -2 if missing from one div; -3 if missing multiple)
    • -2 if a,b divs aren't white
  • 3 block vs. inline: a/b are vertical, and x/y are horizontal
  • 2 borders: on overall #b area, on "a" and "b" divs (and not elsewhere)
  • 2 br: line break between one/two and between three/four, but NOT between two/three
  • 2 margins: a/b divs have 2em margin on all sides (outside the border); no margin between x/y, one/two/three/four
  • 2 padding on right side of "a" / "b" divs (distance from a/b to right border)
  • 2 underline: -2 if underline is applied to any elements
  • 2 width of #b area is half the page; width of a/b divs extends across entire area


  • -1 point each for any other minor misc. stuff they do wrong that isn't listed above

.

[edit] Question 2 (HTML/CSS Coding)

Solution q2.html

HTML:

<div id="main">
    <div id="column1">
        <h1>Zen Garden</h1>

        <div id="slogan">
            <p>A demonstration of...</p>
        </div>

        <div id="enlightenment">
            <h3>The Road to Enlightenment</h3>
            <p>Littering a dark and dreary road lay...</p>
            <p>Today, we must clear the mind...</p>

            <div id="selectadesign">
                <h3>Select Design</h3>
                <ul><li><a href="">Under the Sea!</a> by Eric Stoltz</li>
                    <li><a href="">Make 'em Proud</a> by Michael McAghon and Scotty Reifsnyder</li>...</ul>
            </div>
        </div>
    </div>

    <div id="whatabout">
        <h3>So What is This About?</h3>
        <p>There is clearly a need for CSS to be taken seriously...</p>
        <p>CSS allows complete and total control over the style of a hypertext document.</p>

        <h3>Participation</h3>
        <ul>
            <li>Graphic artists only please. You are modifying this page...</li>
            <li>Zen editors modify the style sheet in any way you wish, but not the HTML.</li>
        </ul>
    </div>
</div>

CSS:

body {
    background-image: url("heading.gif");
    background-repeat: no-repeat;
    color: #471C47;
    font-family: Verdana, sans-serif;
    font-size: 9pt;
}

#main   { margin-left: 130px; }
h1      { display: none; }
#slogan { font-style: italic; }

#selectadesign   { border-top: 3px solid #A690AF; }
#selectadesign a { font-weight: bold; }
#enlightenment {
    background-image: url("toad.png");
    background-repeat: no-repeat;
    background-position: right bottom;
    float: left;
    padding-right: 1em;
    width: 26em;
}

#whatabout {
    background-color: #A690AF;
    border: 2px solid #471C47;
    float: left;
    padding: 1em;
    width: 21em;
}

#whatabout h3 { text-align: right; }

20 points total

  • 1 colors
    • body - color: #471C47;
    • "What's this about?" area - background-color: #A690AF;
  • 4 fonts
    • 1 body font: family Verdana, sans-serif (must have both); font-size 9pt
    • 1 italic "Demonstration" text
    • 2 bold links: in "Select a design" section, font-weight bold
      • (-2 for strong tags in HTML; -2 for making ALL links bold)
  • 4 images
    • 2 header.gif at top-left as div background
      • (-2 if inserted as IMG tag; -1 if they forget background-repeat: no-repeat;)
    • 2 toad.jpg at bottom-right of "Enlightenment/Select" area
      • (-2 if inserted as IMG tag; -1 if they forget background-position: bottom right;)
  • 5 margins, padding, box model
    • 2 130px move content right to avoid header.gif (must be on all of "A demonstration of" thru "Select Design")
    • 1 padding: all around "What's this about" area; on right side of "Enlightenment/Select" area
    • 1 width: 26em for "Enlightenment" area; 21em for "What's this about" area (25em and 19em are okay)
    • 1 border-top/bottom between Enlightenment and Select Design areas
  • 2 headings
    • 1 #whatabout h3 text-align: right;
    • 1 h1 is hidden (display none, or visibility hidden)
  • 4 columns/floating
    • 2 attempt: content is in >= 2 column divs; div(s) float
    • 2 correct: proper divs both float to left


  • other deductions
    • -2 if they try to add any other tags/attributes (id, class, etc.)
    • -2 class/id confusion in their CSS syntax (# vs .)
    • -6 no HTML markup, but CSS makes it obvious what they mean (ask head TA / instructor)

.

[edit] Question 3 (JS/DOM)

window.onload = function() {                        // document.observe is okay
    $("blend").observe("click", blendClick);        // onclick is okay
};

function blendClick() {
    $("output").innerHTML = "";                     // .update() okay
    
    var name = $("yourname").value;                 // .innerHTML NOT okay  (-1)
    var x = 0;
    var y = 0;
    
    for (var i = 0; i < name.length; i++) {
        if ($("sequential").checked) {              // .checked == "checked" NOT okay (-1)
            x = x + 15;
            y = y + 15;
        } else {
            x = parseInt(Math.random() * 300);      // Math.floor is okay
            y = parseInt(Math.random() * 100);      // 301, 101 okay
        }
        var span = document.createElement("span");  // new Element("span") okay
        span.innerHTML = name[i];                   // name.charAt(i) is okay;  .update() okay
        span.style.fontFamily = $("font").value;    // setting on whole output div is okay
        span.style.position = "absolute";
        span.style.left = x + "px";
        span.style.top  = y + "px";                 // setStyle({a:b, c:d, ...}) okay
        $("output").appendChild(span);
    }
}

20 points total

  • 2 window onload (1 attempt, 1 perfect) - attaches click handler
  • 3 loops over characters of name properly (-1 for small error such as OBOB)
  • 7 span/div for each percentage
    • 2 clears previous text properly (removes children or sets output.innerHTML = "")
    • 2 creates and puts text into it; puts onto page in proper DOM place (output.appendChild)
    • 3 CSS properties of each letter span
      • -1 for each missing: fontFamily, position absolute
      • OK (but not required) to set font-family every time select box is modified (onchange)
      • -1 for relative/fixed instead of absolute pos
      • -2 overall if they set ".foo" rather than ".style.foo"
  • 8 positions
    • 4 sequential x/y position (-2 if correct but doesn't start properly at x=15, y=15)
    • 4 random x/y position from (0, 0) to (300, 100)
      • -1 if they forget parseInt/Math.floor
      • -1 if they get the 100 and 300 backwards or use 100 or 300 for both
      • -2 overall if they forget "px" when setting left/top CSS property
      • -3 overall if they set "x" and "y" properties or other distortions, rather than "left" and "top"


  • other deductions
    • -1 for misc. invalid JavaScript (e.g. explode, count, $_REQUEST, etc.)

.

[edit] Question 4 (PHP)

<?php
# ok for letter to preg_match [A-Za-z]
# ok for times  to preg_match [0-9]+;  -1 if times matches just [0-9] or [0-9]*

if (!isset($_REQUEST["letter"]) || !isset($_REQUEST["times"]) ||
        strlen($_REQUEST["letter"]) != 1 || $_REQUEST["times"] <= 0) {
    header("HTTP/1.1 400 Invalid Request");
    die("invalid request");
}

$letter = strtolower($_REQUEST["letter"]);
$times = (int) $_REQUEST["times"];                               # cast to (int) is optional
$matches = 0;
foreach (file("peeps.txt", FILE_IGNORE_NEW_LINES) as $line) {    # file_get_contents/explode ok
    $lowerline = strtolower($line);                              # (explode on letter, check array length) ok
    $count = 0;
    for ($i = 0; $i < strlen($line); $i++) {                     # count($line) ok
        $ch = $lowerline[$i];
        if ($ch == $letter) {                                    # strcmp == 0 okay
            $count++;
        }
    }
    if ($count >= $times) {
        $matches++;
        ?> <p><strong><?= $line ?></strong>
              contains '<?= $letter ?>' exactly <?= $times ?> times.</p>
        <?php
    }
}

if ($matches == 0) {
    ?> <p>No names contained '<?= $letter ?>' enough times.</p>
    <?php
}
?>

20 points total

  • 1 query params
    • 1 $_REQUEST params are read/used properly
  • 4 errors
    • 2 param(s) not passed -> HTTP 400 error
    • 2 param(s) bad value -> HTTP 400 (letter not 1-char string; times not positive int)
      • -2 if they just print the error or die(), but don't use header() to show the HTTP error
  • 10 file/string processing
    • 2 reads / loops over lines of file properly
    • 3 properly detects character ('letter') presence at a given index in string
      • -2 if they preg_split on '.' (consumes all characters)
      • -1 if they explode on "" (causes error at runtime)
    • 2 counts properly and has a proper if/else test to determine whether to print a given name
      • -2 if they misuse regex, e.g. look for 2 consecutive occurrences
      • -2 if they require the count of matches to be exactly == rather than >=
    • 3 string case sensitivity issues
      • -2 if it doesn't match insensitively
      • -1 if they just upper/lowercase everything and this causes matches to lookwrong
  • 5 HTML output
    • 2 paragraph inserted properly with each value
      • -1 for minor formatting issues like forgetting 'quotes' around number, etc.
    • 1 name in bold
    • 2 no matches found case (prints special "not found" message)
  • misc. deductions
    • -1 if they use print/echo ???
    • -1 if they use b tag instead of strong ???
    • -1 for misc. incorrect PHP (e.g. str.length(), split(), if (strcmp(...)), etc.)

.

[edit] Question 5 (SQL)

-- all the times a director has appeared in his own movie, twice --
SELECT DISTINCT d.first_name, d.last_name
FROM directors d
JOIN movies_directors md ON md.director_id = d.id
JOIN roles r1 ON r1.movie_id = md.movie_id
JOIN roles r2 ON r2.movie_id = md.movie_id
JOIN actors a ON a.id = r1.actor_id AND a.id = r2.actor_id
WHERE a.first_name = d.first_name AND a.last_name = d.last_name
  AND r1.role < r2.role
ORDER BY d.last_name, d.first_name;

20 points total

  • 2 SELECT director first/last name (-1 if not DISTINCT)
  • 8 FROM/JOIN
    • 3 directors → movies_directors → movies
    • 1 movies → roles (first role)
    • 2 movies → roles (second role)
    • 2 roles → actors (2 actors OK if linked properly)
      • -2 for each extra table added unnecessarily
      • -2 if table(s) are joined by something other than IDs (e.g. on first/last name)
      • OK to use "FROM table1, table2, ... WHERE a AND b AND c..." syntax if it's right
  • 8 WHERE
    • 3 two roles/actors linked to each other (have same ID or first/last name)
    • 3 actor(s) linked to director (same first/last name)
    • 1 roles unequal (<, >, <>, != allowed)
    • -2 for each extra incorrect constraint if it screws up the query; -0 if it doesn't
  • 2 ORDER BY last name, first name (ok to write ASC; -1 for DESC)
  • other deductions
    • -1 for surrounding their SQL with PHP code
    • -2 for each piece of advanced SQL syntax not taught in class (GROUP BY, HAVING, LEFT INNER JOIN, etc.)

Final 11sp q5 key.png