Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. %Explain program to user
  2. disp('This is a program that will determine the surface area and volume of a hemisphere, cylinder, and rectangular prism.')
  3.  
  4. %Instantiate variables
  5. volumehemi = [];
  6. surfaceareahemi = [];
  7. printhemi = [];
  8. volumecyl = [];
  9. surfaceareacyl = [];
  10. printcyl = [];
  11. volumerect= [];
  12. surfacearearect = [];
  13. printrect = [];
  14.  
  15. %Ask for number of objects
  16. Objnum = input('How many objects would you like to find the surface area and volume of?: ');
  17. %For loop to run x number of times
  18. for i = 1:Objnum
  19. %Prompt for object type
  20. 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');
  21.  
  22. %If loop for Objtypes
  23. hemi = 'hemisphere';
  24. cyl = 'cylinder';
  25. rect = 'rectangular prism';
  26.  
  27. if strcmp(hemi,Objtype)
  28. radiushemi = input('What is the radius of the hemisphere?: ');
  29. surfaceareahemi = 2*pi*radiushemi.^2;
  30. volumehemi = (2/3)*pi*radiushemi.^3;
  31. printhemi = 1;
  32.  
  33. elseif strcmp(cyl,Objtype)
  34. radiuscyl = input('What is the radius of the cylinder?: ');
  35. heightcyl = input ('What is the height of the cylinder?: ');
  36. surfaceareacyl = (2*pi*radiuscyl*heightcyl)+(2*pi*radiuscyl.^2);
  37. volumecyl = pi*heightcyl*radiuscyl.^2;
  38. printcyl = 1;
  39.  
  40. elseif strcmp(rect,Objtype)
  41. length = input('What is the length of the rectangular prism?: ');
  42. width = input('What is the width of the rectangular prism?: ');
  43. height = input('What is the heigth of the rectangular prism?: ');
  44. surfacearearect = 2*(width*length+height*length+height*width);
  45. volumerect = width*height*length;
  46. printrect = 1;
  47.  
  48. end
  49. end
  50.  
  51. if printhemi == 1
  52. disp('The surface area and volume of the hemisphere is:')
  53. disp(surfaceareahemi)
  54. disp(volumehemi)
  55.  
  56. end
  57. if printcyl == 1
  58. disp('The surface area and volume of the cylinder is:')
  59. disp(surfaceareacyl)
  60. disp(volumecyl)
  61.  
  62. end
  63. if printrect == 1
  64. disp('The surface area and volume of the rectangular prism is:')
  65. disp(surfacearearect)
  66. disp(volumerect)
  67.  
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement