ABCs_conditionals - % y is eqaul to 'Cedric' or 'David',...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 function [A B C D] = ABCs_conditionals(x, y, z) % PROBLEM 4. The ABCs of Conditionals % % This is a multi-part problem. Do each of the parts below. % % DO NOT CHANGE THE FUNCTION HEADER (the first line of code) % a) if statements. x is a number. Use an if statement to set A equal to % one of the following strings: 'positive', 'zero', or 'negative' depending % on whether x is positive, zero, or negative. Note that you must use an % if statement and your answer should be stored in a variable named A. % % Write your code here: if x > 0 A = 'positive' elseif x == 0 A = 'zero' elseif x < 0 A = 'negative' end % b) switch statements. The variable y may be equal to one of the % following strings: 'Jacey', 'Andre', 'Taylor', 'Cedric', or'David'. If y % is equal to 'Jacey', 'Andre', or 'Taylor', your answer should be 'TA'. If
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % y is eqaul to 'Cedric' or 'David', your answer should be 'Instructor'. % Otherwise, your answer should be 'Someone Else'. You must use a switch % statement to solve this problem. Store your answer in B. Note that your % answer should be one of the following strings: 'TA', 'Instructor', or % 'Someone Else'. % % Write your code here: switch y case {'Jacey' 'Andre' 'Taylor'} B = 'TA' case {'Cedric' 'David'} B = 'Instructor' otherwise B = 'Someone Else' end % c) any. Use the any() function to determine if any of the values in the % vector z are true. Store your result (true or false) in the variable C. C = any(z) % d) all. Use the all() function to determine if all of the values in the % vector z are true. Store your result (true or false) in the variable D. D = all(z)...
View Full Document

This note was uploaded on 07/06/2009 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

Ask a homework question - tutors are online