User`s manual

Example – Creating and Using a Phone Book
5-81
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” on page 5-79.
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;