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?
      Ans: There are 250 pixels in the image and each pixel would be represented using 24 bits or 3 bytes. So, the total space use to represent the image would be 750 bytes.
    2. How many bytes of memory would be required to represent this horizontal rule as an 8-bit color image?
      Ans: In the 8-bit/indirect version, only one byte would be used for each pixel. These bytes, however, would refer to entries in a color table or palette which would have to hold one entry for each color used. For this image, the palette would have 250 entries each 3 bytes long. So, the palette would be 750 bytes long and the pixel entries themselves would require 250 bytes for a total of 1000 bytes.

  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.

    NOTE: I HAVE NOT PROVIDED A SOLUTION FOR THIS PROBLEM, SINCE THE PARTS OF JAVA WE HAVE COVERED ARE QUITE DIFFERENT FROM THOSE COVERED BY THIS MIDTERM.

    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.
    ANS: (There are many solutions to this problem. Here is a simple one.)
    <IMG SRC="logo.gif" ALIGN=LEFT>
    <IMG SRC="logo.gif" ALIGN=RIGHT>
    <H1 ALIGN=CENTER>WILLIAMS COLLEGE></H1>
    <H1 ALIGN=CENTER>COMPUTER SCIENCE DEPARTMENT</H1>
    <BR CLEAR=BOTH>
    
    

  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.
      True

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

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

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

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

    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.
      True

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

    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.
      False

  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>
      
      Ans: The CENTER tag is illegal within the H3 and FONT tags because it is a block level tag. Using the ALIGN attribute corrects this problem and simplifies the code. One could argue that the use of the FONT tag is inappropriate and that it would be better to simply use a higher level header tag (H1 or H2). Although the code would still be correct if the FONT tag were left, we have made this improvement.
      <H2 ALIGN=CENTER>
      1997-98
      <BR> 
      SOME INTERESTING HEADER
      </H2>
      

    2. <HR size=5>
      
      <TABLE align=left>
      <TD><IMG SRC="guesswhat.jpeg" WIDTH="288" HEIGHT="214"></TD>
      </TABLE>
      <P>
      i don't remember much...
      
      Ans: The TABLE in this example would need a <TR> tag before the <TD> tag to make it correct. In any case, a table containing a single cell is generally overkill. In this case, the only impact the TABLE tag has is the fact that its ALIGN attribute will cause its contents (the image) to float to the left. It is better to simply specify this alignment in the IMG tag.
      <HR size=5>
      
      <IMG SRC="guesswhat.jpeg" align=left WIDTH="288" HEIGHT="214">
      <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>
      
      Ans: This one has several major problems.

      The closing </B> and </FONT> tags after "Vital Stats" are in the wrong order.

      The <LI> tags should only appear with <UL> or <OL> tags.

      The <P> tags around "ESPN" and "MSNBC" are nested within <A>. Since <A> tags are text-level and <P> tags are block-leve, this is illegal.

      There is also a style issues. The phrase "Vital Stats" certainly looks like a header but is enclosed in a TD cell.

      The HTML is sufficiently mal-formed that it isn't terribly clear what the author had in mind, but the following would be a reasonable guess.

      <TABLE>
      <TR>
      	<TH COLSPAN=2 ALIGN=CENTER>
      	   <FONT SIZE=5>Vital Stats</FONT></TD>
      </TR>
      <TR>
              <TD ALIGN=CENTER><UL><LI><A HREF=''http://espnet.sportzone.com''>
                                   ESPN</A></UL></TD> 
              <TD ALIGN=LEFT><UL><LI><A HREF=''http://www.msnbc.com''>
                                   MSNBC</A></UL></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.

    Ans: c -- reduce the average rate at which messages could be delivered.

    This change would make collisions resolution take longer, but it would not fundamentally change the network's ability to resolve collisions. The fact that a station would keep sending after a collision was detected would increase the chance that additional stations would get the urge to send before the network became idle again. This would increase the chance of additional collisions. When stations are involved in multiple collisions, they increase the range from which they pick a random time to wait. Eventually, one station will begin long enough before the others to succeed.