Suppose that a student has the option of enrolling for a single elective during
ID: 3929567 • Letter: S
Question
Suppose that a student has the option of enrolling for a single elective during a term. The student must select a course from a limited list of options: "English, " "History, " "Biology, " "Computer, " or "Math." Construct a fragment of MATLAB code that will prompt the student for his or her choice, read in the choice, and use the answer as the ease expression for a switch construct. Be sure to include a default case to handle invalid inputs. Testing three cases: (a) Computer (b) Physics (c) Biology.Explanation / Answer
disp('The following subjects are available:');
disp('1. English');
disp('2. History');
disp('3. Biology');
disp('4. Computer');
disp('5. Math');
c = input('Please select one of the above courses:(e.g.: 1 for english)');
switch(c)
case 1
disp('You selected English');
case 2
disp('You selected History');
case 3
disp('You selected Biology');
case 4
disp('You selected Computer');
case 5
disp('You selected Math');
otherwise
disp('Invalid input');
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.