CS 10, Spring 1998
Homework 3
Due Dates
- Algorithms (Part A below) are due at the beginning of lab on
Thursday, Feb. 19. These are submitted in printed form.
- The modified stack (Part B below) is due at the beginning of lab on
Thursday, Feb. 26. 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:
- Include your name and the date in comment statements at the
beginning of each modified script.
- Document all modifications you make using program comments (as part of
your scripts).
- Include a title and clear labels as a part of each output display (as
seen in card field results).
This portion of the assignment is to modify the script of your copy of the
"No Account" stack to accomplish two additional tasks.
- 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.
- 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:
- Initialize a counter to 0.
("counter" tells how many of the list's numbers have been seen so far.)
- Initialize a total to 0.
("total" is the sum of those numbers seen so far.)
- For each number in the list,
- add the number to the current total and
- add 1 to the current counter.
- After all the numbers have been seen, divide the total by
the counter.
- Display this as the answer.