Spring 2001 Parks DISC 3371 Midterm Exam Answers

1. (50 points) The server provides the user an HTML page that contains the user's investments. Specifically, the server returns an HTML table where each row contains four text boxes: Name of stock (30 characters); Number of Shares (10 characters); Purchase Price (10 characters); and Current Price (10 characters). Following the table are two buttons labelled: "SHOW GAINS" and "SHOW LOSSES". In addition, following the two buttons is a hidden variable named numrows that contains the number of rows in the table.

When the user clicks on one of the buttons, a single sub named showit is called. This sub produces a new page on-the-fly which creates a new table of either gains or losses. The report produces a multiple row table that shows on each row: (1) the stock name; (2) number of shares; (3) purchase price; (4) current price; and (5) current profit or loss (i.e., number of shares times (current price - purchase price)). The values in the rows are just printed -- they are NOT placed in textboxes. If the "SHOW GAINS" button is pressed the report shows only those stocks where current price is greater than purchase price. If the "SHOW LOSSES" button is pressed the report only shows those stocks where current price is less than purchase price. Nothing is produced in either report if purchase price = current price. The reports should sum the amount of gains or losses and on the last row of the report show total gain or loss. If there are no gains or losses, the report should indicate this condition. The HTML for the two buttons is:

<input type="button" value="SHOW GAINS" onClick="showit(1)">
<input type="button" value="SHOW LOSSES" onClick="showit(2)">

The form on the original HTML page is named sform. SHOW NO HTML. Show ONLY the VBScript code for showit.


ANSWER 1
(Click one of the buttons to see it work - Click View Source to see the code)

Stock NameNumber of SharesPurchase PriceCurrent Price
 


2. (50 points) An html page contains a single textarea named ta and a single button labelled "GO". The user enters a quotation composed of multiple words into the textarea and the clicks the "GO" button. The click causes a sub named bob to be executed. This sub extracts each word from the textarea and stores the result in an array named words. The sub then creates a new page that contains a centered table with a one pixel border. The table has a number of rows equal to the number of words in the quotation. The number of columns in the table is equal to the length of the longest word in the quotation. Each cell in the row contains one character from each word. The row's first cell contains the first character of the word, the second cell contains the second character of the word, etc. For rows that are shorter than the maximum width, the remaining cells of the row contain a single blank character with a cell background color of black. After the table has been displayed, show: (1) the number of words found in the quotation; (2) the length of the longest word; and (3) the length of the shortest word. Show no HTML.

Show ONLY the VBScript code for bob. Assume each word in the quotation is separated by a single space; the last character in the quotatioon is NOT a blank space; and the new table shows the words in same order as the user entered them.


ANSWER:
(Click the button to see it work - Click View Source to see the code)