Final Exam Practice | CS 4, Summer 2007



  1. Below is a JavaScript function with a number of errors. Find each error. In your written answer, number each error and briefly describe the error.
    // this function compares the user entered password (p) against the 
    // actual password (q). The form name is 'myform', and the text object
    // name where the user enters their password is 'password'.
    
    function checkpassword() {
         var p = window.document.myform.password;
         var q = "qIqn0";
         var valid = "1";
    
         if( p.length != q.length ) {
              valid = 0;
         } else {
              for( var k=1 ; k<=p.length ; k++ ) {
                   if( p.charAt(k) != q.charAt(k) ) {
                        valid = 0;
                   }
              }
         }
    
         if( valid = 0 ) {
              window.error( "invalid password" );
              return false;
         }
         return true;
    }
    
  2. Convert the following decimal numbers to signed mantissa and exponent with 7 bits for the mantissa and 7 bits for the exponent: (a) 12.5; (b) -7.125; (c) 0.0625

  3. Give the truth table for the boolean expression: d = (a . b) + not(c) + not(a+c). Draw the circuit for this boolean expression.

  4. We decide that we would like to implement a 3-input OR gate. This gate takes three inputs a,b,c and outputs a+b+c. Draw this gate using three transistors. Your gate should have one power line, three input lines (the transistor switches) and one output line.

  5. Give the Huffman tree for the following Huffman code: a=0 ; b=10 ; c=111 ; d=110 . From just the tree, can you infer the original frequences (if so, what are they; if not, briefly explain why).

  6. Is the following a valid Huffman code: a=0 ; b=1 ; c=011 ; d=010 ; e=001 ? Briefly explain your answer.