⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 phonebook.m

📁 这是机械工业张德丰《MATLAB与外部程序接口编程》随书源码
💻 M
字号:
function phonebook(varargin)
pbname='myphonebook1';   %数字字典命名
if ispc
    datadir=char(java.lang.System.getproperty('user.dir'));
else
    datadir='f:';   %datadir = getenv('HOME');
    pbname=fullfile(datadir,pbname);

    if ~exist(pbname)
    disp(sprintf('Data file %s does not exist.',pbname));
    r=input('Create a new phone book(y/n)?', 's');
    if r=='y',
        try
            FOS=java.io.FileOutputStream(pbname);
            FOS.close
        catch
            error(sprintf('Failed to create %s', phname));
        end;
    else
        return;
    end;
end;

try
    FIS=java.io.FileInputStream(pbname);
catch
    error(sprintf('Failed to open %s for reading.', pbname));
end;

pb_htable.load(FIS);
FIS.close;

    disp ''
    disp 'Phonebook Menu:'
    disp ''
    disp '1. Look up a phone number'
    disp '2. Add an entry to the phone book'
    disp '3. Remove an entry from the phone book'
    disp '4. Change the contents of an entry in the phone book'
    disp '5. Display entire contents of the phone book'
    disp '6. Exit this program'
    disp ''
    s=input('Please type the number for a menu selection:', 's');

    switch s
        case '1',
            name=input('Enter the name to look up:', 's');
            if isempty(name)
                disp 'No name entered';
            else
                pb_lookup(pb_htable, name);
            end;
case '2',
    pb_add (pb_htable);
case '3',
       name=input('Enter the name of the entry to remove:', 's');
       if isempty (name)
       disp 'No name entered'
       else
       pb_remove(pb_htable, name);
       end;
case '4'
       name=input('Enter the name of the entry to change:', 's');
       if isempty(name)
          disp 'No name entered'
       else
          pb_change(pbhtable, name);
       end;
case '5'
    pb_listall (pb_htalbe);
case '6'
    try
        FOS=java.io.FileOutputStream(pbname);
    catch
        error(sprintf('Failed to open %s for writing.',pbname));
    end;
    pb_htable.save(FOS,'Data file for phonebook program');
    FOS.close;
    return;
        otherwise
            disp 'That selection is not on the menu.'
    end;
end;














⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -