Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % 1MW 3B-2/10/16 Justin Bowen
- % Part 2 - Determining Surface Area and Volume
- clear;clc;
- %Explain program to user
- disp('This is a program that will determine the surface area and volume of a hemisphere, cylinder, and rectangular prism.')
- %Instantiate variables
- hemiVolume = [];
- hemiSurfaceArea = [];
- hemiPrint = [];
- cylVolume = [];
- cylSurfaceArea = [];
- cylPrint = [];
- rectVolume= [];
- rectSurfaceArea = [];
- rectPrint = [];
- %Ask for number of objects
- objNum= input('How many objects would you like to find the surface area and volume of?: ');
- %For loop to run x number of times
- for i = 1:objNum
- %Prompt for object type
- 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');
- %If loop for Objtypes
- hemi = 'hemisphere';
- cyl = 'cylinder';
- rect = 'rectangular prism';
- if strcmp(hemi,objType)
- hemiRadius = input('What is the radius of the hemisphere?: ');
- hemiSurfaceArea = 2*pi*hemiRadius.^2;
- hemiVolume = (2/3)*pi*hemiRadius.^3;
- hemiPrint = 1;
- elseif strcmp(cyl,objType)
- cylRadius = input('What is the radius of the cylinder?: ');
- cylHeight = input ('What is the height of the cylinder?: ');
- cylSurfaceArea = (2*pi*cylRadius*cylHeight)+(2*pi*cylRadius.^2);
- cylVolume = pi*cylHeight*cylRadius.^2;
- cylPrint = 1;
- elseif strcmp(rect,objType)
- rectLength = input('What is the length of the rectangular prism?: ');
- rectWidth = input('What is the width of the rectangular prism?: ');
- rectHeight = input('What is the heigth of the rectangular prism?: ');
- rectSurfaceArea = 2*(rectWidth*rectLength+rectHeight*rectLength+rectHeight*rectWidth);
- rectVolume = rectWidth*rectHeight*rectLength;
- rectPrint = 1;
- end
- end
- if hemiPrint== 1
- disp('The surface area and volume of the hemisphere is:')
- disp(hemiSurfaceArea)
- disp(hemiVolume)
- end
- if cylPrint == 1
- disp('The surface area and volume of the cylinder is:')
- disp(cylSurfaceArea)
- disp(cylVolume)
- end
- if rectPrint == 1
- disp('The surface area and volume of the rectangular prism is:')
- disp(rectSurfaceArea)
- disp(rectVolume)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement