CS 105 Midterm Examination
Thursday, Oct. 29, 1998

NAME:

Question Points Score
1 10  
2 15  
3 15  
4 16  
5 18  
6 16  
7 10  
TOTAL 100  
There are 7 questions on this examination. The point values associated with the questions are shown in the table above. You have 75 minutes to complete the examination. You should not consult any references while completing this examination. Show all answers in the spaces provided in the examination booklet. Paper for scrap work will be made available.

  1. Some people get bored with the horizontal rules produced by the HTML <HR> tag and decide to make their own. One can do this by using PhotoShop to create an image just one, two or so pixels high and as wide as you expect your page to be.

    One feature of PhotoShop you can use to produce "nifty" horizontal rules is the "gradient tool". It can be used to fill a region of an image with a range of varying colors. For example, with the gradient tool you can make a horizontal rule that ranges through all the colors of the spectrum.

    Imagine that you made such a rule to use to underline the header of a page with a very thin band of color. Suppose you made the rule just 1 pixel high and 250 pixels wide. Assume you used the gradient tool to construct the rule so that the pixels ranged over the spectrum in such a way that no two pixels had the same color.

    1. How many bytes of memory would be required to represent this horizontal rule as a 24-bit color image?
    2. How many bytes of memory would be required to represent this horizontal rule as an 8-bit color image?

  2. A complete and correct version of a "Color Mixer" applet like the one you constructed in class is shown below. Several questions relating to this applet can be found on the following pages.
    import java.awt.*;
    import javaTools.*;
    
    public class ColorMixer extends AppletTemplate
    {
       Slider redness, greenness, blueness;
    
       
          public void begin() {
    
             redness   = new Slider( 255, 0, 255,180);
             greenness = new Slider( 255, 0, 255,180);
             blueness  = new Slider( 255, 0, 255,180);
             
    
             add(redness);
             add(greenness);
             add(blueness);
             
    
             drawBackground(255,255,255);
          }
          
          private void drawBackground(int r,int g,int b) {
    
                pen.fillRect( new Color(r, g, b));
                                  
    
                pen.fillRect(   0,134, 66,66, ``Red'');
                pen.fillRect(  66,134, 68,66, ``Green'');
                pen.fillRect( 133,134 ,66,66, ``Blue'');   
                
    
                pen.drawString( r, 25,175);
                pen.drawString( g, 81,175);
                pen.drawString( b,147,175);
             }
    
                 
          public void scroll()  {
    
             drawBackground(redness.getValue(),greenness.getValue(),blueness.getValue());
    
             } 
    }
    
    

    1. Suppose the order of the "fillRect" commands in the "drawBackground" method were changed so that the first four lines of this method looked like:
                  pen.fillRect( new Color(r, g, b));
                                    
      
                  pen.fillRect(  66,134, 68,66, ``Green'');
                  pen.fillRect(   0,134, 66,66, ``Red'');
                  pen.fillRect( 133,134 ,66,66, ``Blue'');   
      
      

      Briefly describe how (if at all) this would change the behavior of the applet.

    2. Suppose that the order of the commands in the "drawBackground" method were changed so that the three "drawString" commands came immediately after the first "fillRect". That is the body of the method would look like:
                  pen.fillRect( new Color(r, g, b));
                                    
                  pen.drawString( r, 25,175);
                  pen.drawString( g, 81,175);
                  pen.drawString( b,147,175);
      
                  pen.fillRect(   0,134, 66,66, ``Red'');
                  pen.fillRect(  66,134, 68,66, ``Green'');
                  pen.fillRect( 133,134 ,66,66, ``Blue'');   
      

      Briefly describe how (if at all) this would change the behavior of the applet.

    3. Using the code for the applet shown on the first page of this problem, the top scrollbar displayed will control the "redness" of the background, the middle scrollbar will control the "greenness" and the bottom scrollbar will control the "blueness".

      Show how to modify the applet so that the top scrollbar controls the "blueness", the middle scrollbar still controls the "greenness", and the bottom scrollbar controls the "redness"

      Show your changes on the listing given on the first page of the problem.

      There are many ways to do this. You may show any way that is not unreasonably complicated.

  3. The CS department has finally gotten embarrassed about their boring looking home page. They want to improve its appearance a bit, but they don't quite know where to start. So, for lack of a better idea they are working on a better heading for the page. They simply want the department name to appear centered horizontally and vertically between two copies of an image containing a logo. They want to make sure, however, that this heading will stretch appropriately to fit in large and small browser windows. Samples of what they would like is shown below. On the next page, please provide HTML to place in the BODY of an HTML file that would produce such a header. You may assume the image file is named "logo.gif" and is in the same folder as the .html file.

  4. Indicate whether each of the following statements is true or false:

    1. Frequency division multiplexing can be used with either analog or digital data.

    2. An error-free HTML file will produce identical results when viewed through any web browser.

    3. Increasing the frequency of a wave always decreases its period.

    4. Computer networks based on broadcasting use radio signals sent through the atmosphere rather than wires or fiber interconnecting the machines.

    5. When using the CSMA/CD protocol, increasing a network's speed tends to actually decrease its efficiency.

    6. The "lossy" compression technique used in JPEG files is more likely to distort a simple diagram created with a line drawing program than a digital photograph of a natural scene.

    7. Increasing the thickness of an optical fiber increases the bandwidth available for multiplexing signals.

    8. Two pairs of computers can communicate simultaneously on a token ring as long as the sections of cable that connect the members of each pair do not overlap with the sections connecting the other pair.

  5. Each of the following samples of HTML are a) derived from pages created by CS 105 students (some from this year and some from last year), and b) examples of either incorrect or inappropriate use of HTML.

    For each example, please briefly explain the problems with the HTML shown and indicate how to modify the HTML to make it correct while producing what the author appeared to have in mind. You can either clearly mark up the code shown or write a complete revision in the space provided.

    1. <H3><FONT SIZE=+3><CENTER>
      1997-98
      </CENTER> 
      <BR> 
      <CENTER>
      SOME INTERESTING HEADER
      </FONT></CENTER>
      </H3>
      

    2. <HR size=5>
      
      <TABLE align=left>
      <TD><IMG SRC="guesswhat.jpeg" WIDTH="288" HEIGHT="214"></TD>
      </TABLE>
      <P>
      i don't remember much...
      

    3. <TABLE>
      <TR>
      	<TD COLSPAN=2 ALIGN=CENTER>
      	   <FONT SIZE=5><B>Vital Stats</FONT></B></TD>
      </TR>
      <TR>
              <TD><LI><A HREF=''http://espnet.sportzone.com''>
                                   <P ALIGN=center>ESPN</P></A></TD> 
              <TD><LI><A HREF=''http://www.msnbc.com''>
                                   <P ALIGN=left>MSNBC</P></A></TD>
      </TD>
      </TABLE>
      

  6. Five unlabeled waveforms are shown on the next page. Next to each of the waveforms indicate which of the following might correctly describe the nature of the signal shown. Note: In some cases several descriptions may be appropriate. In such cases list all appropriate descriptions.

    Descriptions:

    1. digital signal represented using manchester encoding

    2. digital signal represented using on-off keying

    3. carrier wave modulated with an analog signal

    4. carrier wave modulated with a digital signal

    5. carrier wave

  7. Recall that the technique on which Ethernet is based is called CSMA/CD -- Carrier Sense Multiple Access with Collision Detection. The "CS" part (Carrier Sense) refers to the fact that each station listens to the network before it starts transmitting and waits if it hears a transmission in progress. The "CD" part (Collision Detection) refers to the fact that while a station is sending its own packet it listens to see if anyone else starts sending at the same time and stops its own transmission if it hears some other station's transmission mixed in with its own.

    Suppose defective ethernet hardware was installed on all the computers on an ethernet so that none of them did the "CD" part correctly. In particular, assume that a) a computer that detects a collision would still be smart enough to try to send the message again later (a random amount of time after it next detects that the network is idle), but b) a computer that detects a collision is not smart enough to stop sending its own message (instead, it keeps sending until the message is complete although certainly not successfully delivered).

    Would such behavior:

    1. Increase the average rate at which message could be delivered,

    2. Have no effect,

    3. Reduce the average rate at which message could be delivered, or

    4. Make it impossible for the network to deliver any messages.

    BRIEFLY, justify your answer.