In the main script use the function input to enter a positive or negative integer. Then, call the function funcif(num) which will rewrite the following switch statement into a nested if-else statement that accomplishes exactly the same thing (plus some modifications). Assign the final result of case (1, 2, 3) to w, case (-4, -3, -2, -1, 0} to x, case 4 to y, and case otherwise to z. Note: Since MATLAB Grader does not have the capability of receiving user input, random integers assigned to variables have been created for you. These random integers will consider all cases in the code below. You may experiment with the input function on your own MATLAB software using the code provided at the top of the template. Special note: For those more interested in computer programming, you may notice the global command. This command is there so that the variables w, x, y, and z are treated globally (i.e. recognized throughout the entire program) instead of locally (i.e. recognized only within the function). switch n case {1,2,3} disp(n/4) case {-4,-3,-2,-1,0} disp(n/3) case 4 disp('A great code!') otherwise disp(n^3) end

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

% n = input('Please enter the value of num: \n');

 

a = randi([1, 3]);

 

b = randi([-4, 0]);

 

c = 4;

 

d = randi([4, 100]); % or -randi([5, 100])

 

funcif(a)

 

funcif(b)

 

funcif(c)

 

funcif(d)

 

global w x y z

 

function funcif(num)

 

if %%%

 

disp(%%%)

 

z = %%%

 

else

 

if %%%

 

if %%%

 

disp(%%%)

 

w = %%%

 

else

 

disp(%%%)

 

x = %%%

 

end

 

else

 

disp(%%%)

 

y = %%%

 

end

 

end

 

end

In the main script use the function input to enter a positive or negative integer. Then, call the function funcif(num) which will rewrite the following switch statement into a nested if-else statement that accomplishes
exactly the same thing (plus some modifications). Assign the final result of case {1, 2, 3} to w, case {-4, -3, -2, -1, 0} to x, case 4 to y, and case otherwise to z.
Note: Since MATLAB Grader does not have the capability of receiving user input, random integers assigned to variables have been created for you. These random integers will consider all cases in the code below.
You may experiment with the input function on your own MATLAB software using the code provided at the top of the template.
Special note: For those more interested in computer programming, you may notice the global command. This command is there so that the variables w, x, y, and z are treated globally (i.e. recognized throughout the
entire program) instead of locally (i.e. recognized only within the function).
switch n
case {1,2,3}
disp(n/4)
case {-4,-3,-2,-1,0}
disp(n/3)
case 4
disp('A great code!')
otherwise
disp(n^3)
end
Transcribed Image Text:In the main script use the function input to enter a positive or negative integer. Then, call the function funcif(num) which will rewrite the following switch statement into a nested if-else statement that accomplishes exactly the same thing (plus some modifications). Assign the final result of case {1, 2, 3} to w, case {-4, -3, -2, -1, 0} to x, case 4 to y, and case otherwise to z. Note: Since MATLAB Grader does not have the capability of receiving user input, random integers assigned to variables have been created for you. These random integers will consider all cases in the code below. You may experiment with the input function on your own MATLAB software using the code provided at the top of the template. Special note: For those more interested in computer programming, you may notice the global command. This command is there so that the variables w, x, y, and z are treated globally (i.e. recognized throughout the entire program) instead of locally (i.e. recognized only within the function). switch n case {1,2,3} disp(n/4) case {-4,-3,-2,-1,0} disp(n/3) case 4 disp('A great code!') otherwise disp(n^3) end
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY