The professors for EAS 230 teach the following lecture sections: Dr. Alaa Hassan
ID: 2325902 • Letter: T
Question
The professors for EAS 230 teach the following lecture sections: Dr. Alaa Hassan All: Sections A and B Dr. William Banas: Section C The TAs for EAS 230 teach the following lab sections: Afsoun: A3, A4, and B4 Mike: A1, A2, and B3 Ge: C1, c2, and C4 Roy. B1, B2, and C3 Using a switch/case structure, write a MATLAB script where the user will Input their lab section (from the keyboard) and the following messages will be displayed: Your professor is . Your TA is . If the lab section entered is not listed above, the script should display: Not a valid lab section!Explanation / Answer
% section takes the input and trims the leading and trailing blank spaces
section = strtrim(input ('Enter your lab section in Capital: ','s'));
% printing the lab section %s is the string variable 'section'
fprintf('Your lab section is %s. ', upper(section));
% upper convert any input to Capital case
% section(1) refers to the first character of the input like if the input is A3 then section(1)= A and section(2)=3
switch upper(section(1))
% case have 2 condition it can take either A or B
case {'A', 'B'}
fprintf('Your professor is Dr Alaa Hassan Ali. ' );
case 'C'
fprintf('Your professor is Dr William Banas. ' );
otherwise
fprintf('Not a valid Lab section ' );
end
switch upper(section)
case {'A3', 'A4', 'B4'}
fprintf('Your TA is Afsoun. ' );
case {'A1', 'A2','B3'}
fprintf('Your TA is Mike. ' );
case {'C1','C2','C4'}
fprintf('Your TA is Ge. ' );
case {'B1','B2','C3'}
fprintf('Your TA is Roy. ' );
otherwise
fprintf('Not a valid Lab section ' );
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.