Goals: Developing problem-solving and using MATLAB Someone has created the follo
ID: 3780250 • Letter: G
Question
Goals: Developing problem-solving and using MATLAB
Someone has created the following code to display the frequency of subway trains in a terminal and the names of the train lines are A, B, C, D and E. Rewrite the code using a switch structure (rather than the nested if), but do not change the prompt. You may assume the user enters an upper case letter at the prompt.
Line = input(‘Enter the line.’,’s’)
if Line > ‘A’ & Line < ‘E’
if Line == ‘C’
disp(‘This train arrives every 12 minutes.’)
else
disp(‘This train arrives every 18 minutes.’)
end
else
if Line == ‘A’
disp(‘This train arrives every 24 minutes.’)
else
if Line ~= E
disp(‘This train is not in service.’)
else
disp(‘This train arrives every 30 minutes.’)
end
end
end
Line input Enter the line. 's') if Line IA' & Line 'E' if Line 'C' disp This train arrives every 12 minutes. else disp This train arrives every 18 minutes. end else Ar if Line disp (This train arrives every 24 minutes.') else if Line E disp T his train is not in service. else disp ('This train arrives every 30 minutes.') end end endExplanation / Answer
Line = input('Enter the line.','s')
switch Line
case 'A'
disp('This train arrives every 24 minutes.')
case 'B'
disp('This train arrives every 18 minutes.')
case 'C'
disp('This train arrives every 12 minutes.')
case 'D'
disp('This train arrives every 18 minutes.')
case 'E'
disp('This train arrives every 30 minutes.')
otherwise
disp('This train is not in service')
end
% A - 24
% B - 18
% C - 12
% D - 18
% E - 30
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.