CS 10, Fall 1997 (Section 1)

Lab 5, Part II: Scripting with HyperTalk (continued)

The purpose of this lab is to give you more practice scripting in HyperTalk. Now is a good time for you to straighten out any problems or questions you have about the reading or labs we've done so far in module 4. By the end of this lab you should start to be feeling fairly fluent in HyperTalk. Be sure to ask us questions if you don't understand something.

Assignment for the Next Lab

Write answers to the Review Questions on page 144. Also write answers to questions 8-10 and 12 on pp 167-168.

Read pages 154-158 before next lab period.

Hand in part A of Homework #3 (see homework description below).


Lab 5, Part II Instructions

  1. First copy the merryxmas Vaccine from the classes server onto your disk. Open the vaccine and use it to check all the stacks on your disk for the merryxmas virus.

  2. Finish up the first part of lab 5 if you didn't on Thursday. When you finish, show us your find/replace stack and if you didn't finish it last lab, your greeting card.

  3. Do Lab exercises 4.1 and 4.2 on page 144 in your book. When you have finished, call one of us over to show us your modified stack.

  4. If there is still time remaining in class, modify the stack No Account so that it allows the user to request that the account information for a given account id be displayed in the card field "results." This will require creating a new field where the user can enter the account id, and a new button which will search through card field "data" and display in card field "results" the appropriate line from card field "data."

Due Dates

  1. Algorithms (Part A below) are due at the beginning of lab on Thursday, Sept. 25. These are submitted in printed form.

  2. The modified stack (Part B below) is due at the beginning of lab on Thursday, Oct. 2. This is submitted on a diskette.

Homework Description

A. Algorithms

You are asked below to modify several of the "No Account" scripts. Before you begin editing these scripts, write down an English description of your algorithm (or recipe) for solving the problems. (An example algorithm is given below in Part C.) Submit a printed version of your algorithms on Thursday, Sept. 25.


B. Script Modifications

Documentation is an important part of producing adaptable code and informative displays. Your work on the "No Account" script should: This portion of the assignment is to modify the script of your copy of the "No Account" stack to accomplish two additional tasks.

  1. Edit the script of button "Average balance" so that, after calculating and displaying the average balance, it then determines and displays the number of accounts with greater than average balances and the number of accounts whose balances are no more than average. The new calculations should be done in a separate handler which can be called (invoked) from the MouseUp handler. You will need to use a parameter to pass the current average balance from the MouseUp handler to your new handler. Your new handler should also display the Names, IDs and Balances (in this order) for the accounts, grouped according to whether the balance is above or below average.

  2. Create a new button that calculates and displays in field "Results" a listing of IDs, #Payments Remaining and Balances (in this order) for accounts that have less than six payments remaining. Name this button appropriately.
Remember that you can always retrieve a clean copy of the "No Account" stack from the file server if you accidentally mess up your copy.


C. Algorithm Example

Problem:
Determine and display the average value of a list of numbers.

First pass solution:
Divide the sum of the numbers on the list by how many numbers the list contains; display this quotient.

After some refinement, an algorithm to solve this problem might look like:

  1. Initialize a counter to 0. ("counter" tells how many of the list's numbers have been seen so far.)

  2. Initialize a total to 0. ("total" is the sum of those numbers seen so far.)

  3. For each number in the list,
    • add the number to the current total and
    • add 1 to the current counter.

  4. After all the numbers have been seen, divide the total by the counter.

  5. Display this as the answer.