Advertisement
MnMWizard

matlab assignment 3

Sep 30th, 2019
611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.28 KB | None | 0 0
  1. %Mason Marnell - Assignment 3
  2. % remember, don't just deadass copy paste pls
  3.  
  4. %%
  5. %Question 1
  6. dept = menu("Select what Engineering Deparptment you are in: ", 'Civil Engineer','Chemical Engineer','Computer Engineer','Electrical Engineer','Mechanical Engineer');
  7. CredHours = 0;
  8. disp(dept);
  9. switch dept
  10.     case 1
  11.         CredHours = 135;
  12.     case 2
  13.         CredHours = 135;
  14.     case 3
  15.         CredHours = 125;
  16.     case 4
  17.         CredHours = 130;
  18.     case 5
  19.         CredHours = 128;
  20. end
  21. fprintf('You need a minimum of %d credit hours',CredHours);
  22.  
  23. %%
  24. %Question 2
  25. inp = input("Input X, y/Y, or Q   ","s");
  26. if inp == "X"
  27.     disp("Hello");
  28. elseif inp == "Y" || inp == "y"
  29.     disp("Yes");
  30. elseif inp == "Q"
  31.     disp("Quit");
  32. else
  33.     disp("Error");
  34. end
  35.  
  36. %%
  37. %Question 3 - switch the code to a switch/case version
  38.  
  39. code = lower(input("Input A, B, C , D, or E:   ","s"));
  40.  
  41. switch code
  42.     case "b"
  43.         fprintf("Every 7 minutes\n");
  44.     case "c"
  45.         fprintf("Every 10 minutes\n");
  46.     case "d"
  47.         fprintf("Every 7 minutes\n");
  48.     case "a"
  49.         fprintf("This line is now obsolete!\n");
  50.     case "e"
  51.         fprintf("Error - there is no such trolley!\n");
  52.     otherwise
  53.         fprintf("Every 12 minutes\n");
  54. end
  55.  
  56. %%
  57. %question 4
  58.  
  59. wind = input("Input the wind speed: ");
  60.  
  61. if (wind >= 74 && wind <= 95)
  62.     disp("Category 1 storm, with a minimum surge of 4.")
  63. elseif (wind >= 96 && wind <= 110)
  64.     disp("Category 2 storm, with a minimum surge of 6.")
  65. elseif (wind >= 111 && wind <= 130)
  66.     disp("Category 3 storm, with a minimum surge of 9.")
  67. elseif (wind >= 131 && wind <= 154)
  68.     disp("Category 4 storm, with a minimum surge of 13.")
  69. elseif (wind >= 155)
  70.     disp("Category 5 storm, with a minimum surge of 18.")
  71. else
  72.     disp("This storm is not large enough to have a category.")
  73. end
  74.  
  75. %%
  76. %question 5
  77.  
  78. %"Your friend who smokes cigarettes wants to know the total amount of
  79. %people he's made frown over time. Since he makes about 5 people a day
  80. %frown, write a loop that will add up that number of people for a given
  81. %amount of days."
  82.  
  83. smonk = input("How many days do you want to calculate total frowns for? ");
  84. sum = 0;
  85. for i = 0:1:smonk
  86.     sum = sum + 5;
  87. end
  88.  
  89. fprintf("Your friend has made around %d people frown over time. Wow!", sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement