MIS 3371 PARKS MIDTERM ANSWERS FALL 2010

Project Gutenberg 10/17/2010
Top 50 Downloaded Books

1. (50 points) The textarea (named t) is in a form named f1 (shown to the left) that contains Project Gutenberg's latest list of most often downloaded books (Project Gutenberg provides free downloads of famous books). The list contains the top 50 books downloaded on Oct. 17, 2010. The format of the list is:
   Title,
   Author,
   Number of downloads for the day,

Each entry is separated from the next by a comma. Thus, there are 150 comma separated items (50 book titles, 50 authors and 50 counts). The button labelled "Execute p1" causes a vbscript sub named p1 to be executed. The sub p1:
  1. creates a NEW HTML page on-the-fly
  2. this new page contains:
    1. A 50 row, 4 column table where each row contains:
         (a) the row number (1 to 50);
         (b) the author;
         (c) the book title;
         and (d) download count
    2. The total number of downloads shown after the end of the table
Show NO HTML. Show ONLY the vbscript code for the sub named p1.

This is a DIV block with id="p2_out
2. (50 points) In the textarea to the left is the first chapter of Theodore Roosevelt's book "The Winning of the West" (1896). This textarea is named tr and is in a form named f2. There is also a button labelled "Execute p2" which when clicked executes a javascript function name p2. The function p2 performs the following actions:
  1. retrieves the text from the textarea named tr
  2. removes ALL the commas in the string (i.e., replaces them with the empty string "")
  3. defines an output string named tr_out and sets this string's initial value to:
    "The capitalized words are: <p>"
  4. divides the text retrieved into sentences (sentences are separated by periods)
  5. for EACH sentence, the code then divides EACH sentence into words (words are separated by a space)
    1. searches each sentence for words that begin with a capital letter (i.e., they begin with an "A", "B", "C", ... , "Z")
    2. start your search of the sentences with the THIRD WORD in each sentence (i.e., DO NOT SHOW the FIRST WORD in the sentence).
      [Note: since the sentences were split using the period, sentences begin with a blank, so the first word is always an empty string, and the second word is the first "real" word. By starting with the third word, the initial "real" word is not to be considered. For example, the sentence " In the city of Atlantis..." has a word array split on the " ", so:
      word[0]="", word[1]="In", word[2]="the", word[3]="city", word[4]="of", word[5]="Atlantis",...
      By starting with the THIRD word, we can omit the capitalized word at the beginning of the sentence.]
    3. append the capitalized words found (as described above) to the tr_out string and then add a comma and a space
  6. count the words as they are appended to the tr_out string (name this counter nw).
  7. when done, in the DIV block with id="p2_out":
    1. place the tr_out string
    2. followed by the count of capitalized words (i.e., the value of nw)

Assume an array named caps is already is defined in p2 like this:
      var caps=new Array ("A","B","C","D",...,"Z");

Show NO HTML. Show only the javascript for p2.