Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %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
- volumehemi = [];
- surfaceareahemi = [];
- printhemi = [];
- volumecyl = [];
- surfaceareacyl = [];
- printcyl = [];
- volumerect= [];
- surfacearearect = [];
- printrect = [];
- %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)
- radiushemi = input('What is the radius of the hemisphere?: ');
- surfaceareahemi = 2*pi*radiushemi.^2;
- volumehemi = (2/3)*pi*radiushemi.^3;
- printhemi = 1;
- elseif strcmp(cyl,Objtype)
- radiuscyl = input('What is the radius of the cylinder?: ');
- heightcyl = input ('What is the height of the cylinder?: ');
- surfaceareacyl = (2*pi*radiuscyl*heightcyl)+(2*pi*radiuscyl.^2);
- volumecyl = pi*heightcyl*radiuscyl.^2;
- printcyl = 1;
- elseif strcmp(rect,Objtype)
- length = input('What is the length of the rectangular prism?: ');
- width = input('What is the width of the rectangular prism?: ');
- height = input('What is the heigth of the rectangular prism?: ');
- surfacearearect = 2*(width*length+height*length+height*width);
- volumerect = width*height*length;
- printrect = 1;
- end
- end
- if printhemi == 1
- disp('The surface area and volume of the hemisphere is:')
- disp(surfaceareahemi)
- disp(volumehemi)
- end
- if printcyl == 1
- disp('The surface area and volume of the cylinder is:')
- disp(surfaceareacyl)
- disp(volumecyl)
- end
- if printrect == 1
- disp('The surface area and volume of the rectangular prism is:')
- disp(surfacearearect)
- disp(volumerect)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement