a)
Code Block | ||
---|---|---|
| ||
function personProgram ()
choice = -1;
P = [];
printHeader();
while choice ~= 0
printMenu();
choice = input ('Velg et tall: ');
clc
if choice == 0
continue;
end
P = process(P, choice);
end
printFooter();
end |
...
Code Block |
---|
function printFooter () fprintf('Programmet avsluttes .\n'); end |
e)
Code Block | ||
---|---|---|
| ||
function P = processLoad () fprintf ('Skal laste en fil \n'); end function processStore(P) fprintf('Skal lagre en fil \n'); end function processListPersons(P) fprintf('Skal skrive ut personene \n'); end function P = processNewPerson(P) fprintf('Skal legge til en ny person \n'); end function P = processChangePerson(P) fprintf('Skal endre en person \n'); end |
f)
Code Block | ||
---|---|---|
| ||
function P = process (P, choice ) fprintf ('\n'); switch choice case 1 P = processLoad(); case 2 processStore(P); case 3 processListPersons(P); case 4 P = processNewPerson(P); case 5 P = processChangePerson(P); otherwise fprintf ('%s\n', 'Ugyldig valg '); end fprintf ('\n'); end |
...
Code Block |
---|
function processStore(P) filename = input ('Hvilken fil vil du lagre til ? ', 's'); store(filename, P); end |
i)
Code Block | ||
---|---|---|
| ||
function processListPersons(P)
listPersons(P);
end % unødvendig, ja :) |
j)
Code Block |
---|
function [newListOfPersons] = processNewPerson(listOfPersons) newData=batchRegisterPersons(); newListOfPersons=[listOfPersons,newData]; end |
...