Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. % 1MW 3B-2/10/16 Justin Bowen
  2. % Part 2 - Determining Surface Area and Volume
  3. clear;clc;
  4. %Explain program to user
  5. disp('This is a program that will determine the surface area and volume of a hemisphere, cylinder, and rectangular prism.')
  6.  
  7. %Instantiate variables
  8. hemiVolume = [];
  9. hemiSurfaceArea = [];
  10. hemiPrint = [];
  11. cylVolume = [];
  12. cylSurfaceArea = [];
  13. cylPrint = [];
  14. rectVolume= [];
  15. rectSurfaceArea = [];
  16. rectPrint = [];
  17.  
  18. %Ask for number of objects
  19. objNum= input('How many objects would you like to find the surface area and volume of?: ');
  20. %For loop to run x number of times
  21. for i = 1:objNum
  22. %Prompt for object type
  23. objType = input('What type of object would you like to find the surface area and volume of?\nPlease type hemisphere, cylinder, or rectangular prism: ','s');
  24.  
  25. %If loop for Objtypes
  26. hemi = 'hemisphere';
  27. cyl = 'cylinder';
  28. rect = 'rectangular prism';
  29.  
  30. if strcmp(hemi,objType)
  31. hemiRadius = input('What is the radius of the hemisphere?: ');
  32. hemiSurfaceArea = 2*pi*hemiRadius.^2;
  33. hemiVolume = (2/3)*pi*hemiRadius.^3;
  34. hemiPrint = 1;
  35.  
  36. elseif strcmp(cyl,objType)
  37. cylRadius = input('What is the radius of the cylinder?: ');
  38. cylHeight = input ('What is the height of the cylinder?: ');
  39. cylSurfaceArea = (2*pi*cylRadius*cylHeight)+(2*pi*cylRadius.^2);
  40. cylVolume = pi*cylHeight*cylRadius.^2;
  41. cylPrint = 1;
  42.  
  43. elseif strcmp(rect,objType)
  44. rectLength = input('What is the length of the rectangular prism?: ');
  45. rectWidth = input('What is the width of the rectangular prism?: ');
  46. rectHeight = input('What is the heigth of the rectangular prism?: ');
  47. rectSurfaceArea = 2*(rectWidth*rectLength+rectHeight*rectLength+rectHeight*rectWidth);
  48. rectVolume = rectWidth*rectHeight*rectLength;
  49. rectPrint = 1;
  50.  
  51. end
  52. end
  53.  
  54. if hemiPrint== 1
  55. disp('The surface area and volume of the hemisphere is:')
  56. disp(hemiSurfaceArea)
  57. disp(hemiVolume)
  58.  
  59. end
  60. if cylPrint == 1
  61. disp('The surface area and volume of the cylinder is:')
  62. disp(cylSurfaceArea)
  63. disp(cylVolume)
  64.  
  65. end
  66. if rectPrint == 1
  67. disp('The surface area and volume of the rectangular prism is:')
  68. disp(rectSurfaceArea)
  69. disp(rectVolume)
  70.  
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement