DISC 3371 Final
Parks Spring 2004

1. (50 points) Customers of a financial trading firm can request a report of the annual trading price for any stock they own. They specify their request by entering a stock trading symbol and the year they want to see in the report. The server then returns the information in XML format and places the information in an "XML data island". The data island has an id="stock_prices". The XML has an outside tag named <stock> followed by: a <stock_symbol>, <stock_name> the <year> tags. The trading price data then follows. For each trading day there are two tags: <date> (which stores the trading date) and <price> (which stores the closing stock price for that trading day).

An example of this data island is shown at the left. The closing prices for "Dewey, Cheatem and Howe" (stock symbol "DCH") are shown for "2003" in the data island named stock_prices. There are 255 trading date/prices reported for 2003 (Note that days 6 through 249 have been omitted for printing brevity -- BUT THEY ARE in the XML data island as sent by the sever). Thus there are a total of 514 tag pairs (1 outside pair; 1 pair each for: stock_symbol; stock_name; and year and 255 date tag pairs and 255 price tag pairs).

Write the Javascript function named ol that is executed when the page is loaded. This function uses the XML DOM to retrieve the relevant data from the page. Store the daily date values in an array named d and the closing stock price values in an array named p. The function then produces a report on-the-fly that contains:
  1. The stock name, stock symbol and year at the top of the page
  2. A table with one row per trading day. The first column contains the date and the second column contains the closing stock price.
  3. The average closing price for the year
The body of the HTML page when received has only one component: the XML data island with the requested data (Note that the id of the XML data island is always named stock_prices and the root tag is always named stock). There are no headings in the output. Show only the Javascript for the function ol (Show NO HTML).
Click here to see the answer for problem #1. Click "VIEW", then "SOURCE" to see the code
2. (50 points) Assume a 255 element array named p (as in the previous problem) has stored in it the values for 255 trading day prices (beginning at array position zero). Assume that this array and the array element values have been defined in a VBScript sub named g. When the page is loaded, execute the sub g and create a new page on-the-fly that contains a graph of the daily prices (like the graph shown to the left for example). Use multiple copies of the image file named b1x1.gif -- a one pixel by one pixel image containing a single black pixel -- to create the graph.
You can position the image files that make the graph by using a "styled span block" and the image file like this:
 
<span style="position:absolute; Top:yyypx; Left:xxxpx; "> <img src="b1x1.gif"> </span>

for each data point you wish to graph. Here the value of yyy would represent the number of pixels from the top of the page and xxx would represent the number of pixels from the left margin. The graph should be 150 pixels tall and 255 pixels wide. Scale the data so that the maximum price is at the top (i.e., "Top:0px" in the span block) and the minimum price is 149 pixels from the top (i.e., "Top:149px" in the span block). The first price is 1 pixel from the left (i.e., the horizontal position for p(0) is "Left:1px" in the span block; p(1) is "Left:2px" in the span block; p(2) is "Left:3px" in the span block;... etc.).

The graph will therefore be 255 pixels wide and 150 pixels tall. The page will contain 255 "styled span blocks" and 255 copies of the b1x1.gif image. Do NOT draw the black box border around the graph as shown above (Show NO HTML, just the code for the VBScript sub named g).

Click here to see the answer for problem #2. Click "VIEW", then "SOURCE" to see the code