External Interfaces/API |
Description of Function pb_change
1. Find the Entry to Change, and Confirm
Arguments passed to pb_change
are the Properties
object pb_htable
and the name
key for the requested entry. The pb_change
function calls get
on pb_htable
with the name
key, on which pb_keyfilter
is called to change spaces to underscores. The get
method returns the entry (or null
, if the entry is not found) to variable entry
. pb_change
calls isempty
to determine whether the entry is empty. If the entry is empty, pb_change
displays a message that the name will be added to the phone book, and allows the user to enter the phone number(s) for the entry.
If the entry is found, in the else
clause, pb_change
calls pb_display
to display the entry. It then uses input to ask the user to confirm the replacement. If the user enters anything other than y
, the function returns.
function pb_change(pb_htable,name) entry = pb_htable.get(pb_keyfilter(name)); if isempty(entry) disp(sprintf('The name %s is not in the phone book', name)); return; else pb_display(entry); r = input('Replace phone numbers in this entry (y/n)? ','s'); if r ~= 'y' return; end; end;
2. Input New Phone Number(s) and Change the Phone Book Entry
pb_change
uses disp
to display a prompt for new phone number(s). Then, pb_change
inputs data into variable entry
, with the same statements described in 1. Input the Entry to Add.
Then, to replace the existing entry with the new one, pb_change
calls put
on pb_htable
with the (filtered) key name
and the new entry. It then displays a message that the entry has been changed.
disp 'Type in the new phone number(s), one per line.' disp 'To complete the entry, type an extra Enter.' disp(sprintf(':: %s', name)); entry=[name '^']; while 1 line = input(':: ','s'); if isempty(line) break; else entry=[entry line '^']; end; end; pb_htable.put(pb_keyfilter(name),entry); disp ' ' disp(sprintf('The entry for %s has been changed', name));
Description of Function pb_remove | Description of Function pb_listall |