MIS 3371 - PARKS - MIDTERM - SPRING 2012

For coding answers, click "View", then "Source" -- click the buttons below to see the code execute

 Texians at the Battle of San Jacinto
April 21, 1836
1. (50 points) The textarea (named sanjac) shown to the left is in a form named f1 that contains the names of the 870 known soldiers at the Battle of San Jacinto fought in what is now Harris County, Texas on April 21, 1836 (Note: many names have been omitted in the display to the left -- but there are 870 soldiers listed in the actual textarea used in the code). For each soldier there are four pieces of data separated by commas. The format of the data in the textarea is:

  • last name followed by a comma;
  • first name and sometimes a middle name and/or initial; followed by a comma;
  • if they held rank, a string with their rank (otherwise nothing); followed by a comma;
  • either: the letter W if wounded; the letter K if killed; or nothing; followed by a comma.

So, each soldier has 4 fields: last name; first name (and maybe an initial); rank (or maybe nothing); W or K or nothing; each followed by a comma. Produce a report "on-the-fly" with the following three items:

  1. A count of the number who were wounded in the battle (i.e., how many times "W" occurs in the fourth field)
  2. A count of the number who were killed in action (i.e., how many times "K" occurs in the fourth field)
  3. A table of the names of all the soldiers who held rank (i.e., the rank field -- field three -- is NOT empty). Show one soldier on each row. In column 1 place: their last name, followed by first name and/or initial; in column 2 place their rank.
The button labelled "Execute p1" causes a vbscript sub named p1 to be executed. Show NO HTML. Show ONLY the vbscript code for the sub named p1.

Data from:

http://freepages.genealogy.rootsweb.ancestry.com/~genbel/states/texas/battleofsanjacinto.html

 

 ADD'EM UP 

Number of rows

Number of columns

Below is this DIV block with id="p2_out":

2. (50 points) Two textboxes shown to the left each contain a single numeric digit. They are in a form named f2. The first textbox is named nr and is to be used to define the number of rows in a table you are to produce. The second textbox is named nc and is to be used to define the number of columns in the table you are to produce. When the button labelled "Execute p2" is clicked, a javascript function named p2 is executed. Assume that the function p2 has these statements (bold-faced below) at the beginning (don't waste time writing them down):
var rt=new Array(); this array will contain the total of the cell values in each row (initialize the nr array to 0)
var ct=new Array(); this array will contain the total of the cell values in each column (initialize the nc array to 0)
gt=0; this variable will contain the totals of ALL the cell values in the table
cellval=1; this variable will be used as the value for each cell, cellval increases by 1 as each cell is created
os="<table border='1'>"; this string will contain the final output to be displayed in the DIV block with id="p2_out"
The function then produces a table with nr rows and nc columns. Each cell contains a number (i.e., cellval). The first cell contains a 1, the next a 2, the next a 3, etc. (i.e., as each cell is added to the table, the value in the cell is the previous cell's value plus one). Using i and j as the row and column indices, respectively, as each table cell is created:

  • the value in the cell is added to the appropriate row total in the array rt (i.e., rt[i] ) AND;
  • added to the appropriate column total in the array ct (i.e., ct[j] ) AND;
  • added to the grand total named gt.
  • In addition to the table cells above, show the row total (i.e., rt[i] ) in an additional cell at the end of the row, AND;
  • at the end of the original table, show another row with ALL the column totals (i.e., all ct[j] ) and then the grand total ( gt ).
  • When done, assign the value of os to the p2_out DIV block.
  • All the row, column and grand totals have a background color of gray.

    Note: the final table displayed in p2_out will actually have (nr+1) rows and (nc+1) columns.

    Show NO HTML. Show ONLY the javascript code for the function named p2.