Q:

Write a function that will receive a name and department as separate strings and will create and return a code consisting of the first two letters of the name and the last two letters of the department

0

 Write a function that will receive a name and department as 

separate strings and will create and return a code consisting of the first

two letters of the name and the last two letters of the department. 

The code should be upper-case letters. For example,

>> namedept('Robert','Mechanical')

ans =

ROAL

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

nameDept.m

function outcode = nameDept(name, department)

% Creates a code from a name and department

% consisting of first two letters of the name

% and the last two of the department, upper case

% Format of call: nameDept(name, department)

% Returns the 4-character code

outcode = name(1:2);

outcode = upper(strcat(outcode, department(end-1:end)));

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now