COMP 110

Midtem Exam


This exam is closed book, closed notes, closed classmates. You have 75 minutes to complete it.

Please put all answers on the test sheets. Make sure your answer is clearly marked and easily distinguished from work you do to get to the solution. You should show your work for partial credit.

When done, please staple together your exams sheets and any paper you use for work and place it face down on the lecture table. Please please print your name clearly below, and sign when you hand in the exam, signifying your adherence to the honor code and attesting to the work being yours alone.

Name (print) ----------------------------------------------------------------


Signed  ---------------------------------------------------------------------

  1. (8%) Give a one sentence description of what each HTML tag does
    (a) < br/ >
    
    
    (b) < h2 >
    
    
    (c) < body >
    
    
    (d) < script >
    
    
    

  2. (3%) Select the item that best completes the following.
    I have a JavaScript program that I want to put into an HTML document. I want it to run before any information is rendered to the screen by the browser. I should put that script
    (a) in the head section
    (b) between the head section and the body section
    (c) right after the < h1 > header in the body section
    (d) at the end of the body section 
    
    
    answer: __ a _________  
    
    

  3. (3%) Select the answer that best defines "call by value"
    (a) parameters are passed to a function in the increasing 
        order of their importance to the algorithm
    (b) when two function calls appear in one expression 
        ( like abs(x)+round(y) ) they are called in alphabetic order 
        according to their names
    (c) parameters are passed to a function by evaluating each
        expression in the call and sending in the resulting values
    (d) variable names must be chosen so that they have descriptive
        value to people reading the program  
    
    
    answer: __ c ___________ 
    
    

  4. (6%) Define the following terms... use a sentence or two for each definition.
    (a) fetch and execute cycle
    
    
    
    
    (b) CPU
    
    
    
    
    (c) byte 
    
    
    
    

  5. (6%) What are the 6 fundamental technical concepts we have learned for programming... give a name, and a brief (one sentence) definition for each one.
    (1)
    
    
    
    
    (2)
    
    
    
    
    (3)
    
    
    
    
    (4)
    
    
    
    
    (5)
    
    
    
    
    (6)
    
    
    
    
    

  6. (4%) What is the binary representation of the decimal number 25? Show your work or explain your reasoning for partial credit.
      
    
    
    
    answer: __ 11001 _______
    
    

  7. (4%) What is the decimal representation of the binary number 10011101? Show your work or explain your reasoning for partial credit.
      
    128+0+0+16+8+4+0+1
    128+29
    157
    
    answer: __ 157 ________
    
    

  8. (15%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       var max = 6;
       var num = 0;
       var k = 0;            // loop index
       while (k < max) {
          num = num + k;
          k = k + 1;
       }
       alert(num);
    
    
    
    
    answer: __ 15 __________  
    
    

  9. (15%) What is printed in the "alert" box at the end of running function "doesSomething()" ?
       function doesSomething () {
          var num = 16;
          var res = 5;
          res = cruncher(num);
          alert("num: " + num + ", res: " + res);
       }
    
       function cruncher (aParm) {
          aParm = aParm * 2;
          return aParm;
       }
    
    
    
    
    answer: ____ num: 16, res: 32 _____  
    
    
    

  10. (10%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       var x = 5;          
       var f = 5;
    
       if (x < 10 ) { x = x + 1; }
       else if (x == 5) { x = x - 2 ; }
       else if (x > 0) { x = x * 3; }
       else { x = -8 ; }
    
       if (f < 10 ) { f = f + 1; }
       if (f == 5) { f = f - 2 ; }
       if (f > 0) { f = f * 3; }
       else { f = -8 ; }
    
       alert("x: " + x + ", f: " + f);
    
    
    
    
    answer: ___ x: 6, f: 18  ________ 
    
    
    
    
    

  11. (10%) What is printed in the "alert" box at the end of running this JavaScript code fragment?
       var i;            // loop index
       var flag = true;
    
       for (i=0; i<5; i++) {
          flag = !flag ;
       }
    
       alert(flag);
    
    
    
    answer: __ false ________ 
    
    

  12. (20%) Write a JavaScript function called "findSmallest" that takes two parameters: an array of numbers, and the size of the array. The function returns the index of the smallest element (note that I am not asking you to return the smallest value itself... I want the function to tell me where in the array the smallest value is found). Use the following code as a template, and add your function to it, on this paper.
    function exam1 ( ) {
    
      var max = 100;
      var arr = new Array(max);
      var sLoc = -1; 
    
      getData(arr); // assume this function loads the array with data somehow;
                    // you do not need to write this function
      sLoc = findSmallest(arr,max);
      alert("smallest value is here: "+sLoc);
    }
    
    // write your function findSmallest to go here