using matlab pls Problem-4: Strings Write a function createCode that will receiv
ID: 2248632 • Letter: U
Question
using matlab pls
Problem-4: Strings Write a function createCode that will receive a student name and his/her department name as separate strings. Using the built-in ischar and length) functions, your createCode ) function should check whether the inputs are characters and have the appropriate lengths prior to generating a code consisting of the last two letters of the name and the first three letters of the department name. The code should be in uppercase (upper). Sample runs of the function are provided as follow: >>createCode(David', 'Engineering) IDENG >>createCode('David, 'En') Your inputs must be strings and have lengths greater or equal to 2 or 3!Explanation / Answer
function Code = CreateCode()
prompt = {'Enter the name of the student: ','Enter the Deptt. Name: '};
dlg_title = 'Inputs';
num_lines = 2;
def = {'XXX','YYY'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
Name = answer{1};
Deptt = answer{2};
l_Name = length(Name);
if(l_Name < 3), disp('Name Error - Not a Valid Name -> MInimum length should be 2.'); CreateCode(); end
for r=1:l_Name
temp = Name(r);
if(temp < 65),
disp('Name Error: No numeric value is allowed'); CreateCode();
end
end
l_Deptt = length(Deptt);
if(l_Deptt < 4), disp('Deptt Error - Not a Valid Deptt. Name -> MInimum length should be 3.'); CreateCode(); end
for r=1:l_Deptt
temp = Deptt(r);
if(temp < 65),
disp('Deptt Error - No numeric value is allowed'); CreateCode();
end
end
Code = upper(strcat(Name(l_Name-1),Name(l_Name),Deptt(1),Deptt(2),Deptt(3)))
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.