CS 105 Midterm Examination
Thursday, Oct. 29, 1998
NAME:
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.
Question Points Score 1 10 2 15 3 15 4 16 5 18 6 16 7 10 TOTAL 100
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.
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.
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.
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());
}
}
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.
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.
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.
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>
True
False
True
False
True
True
False
False
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.
<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>
<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...
<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>
Descriptions:
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:
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.