Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7. Write a function that will calculate the volume of a barbell made of two sphe

ID: 1885722 • Letter: 7

Question

7. Write a function that will calculate the volume of a barbell made of two spheres connected by a bar. You will pass the radius of the spheres, the radius of the cylinder and the length of the cylinder. Write a program (script) that inputs the radius of the spheres, the radius of the cylinder and the length of the cylinder and calls the function to calculate the volume. Display the result in the script as "The volume of a barbell with two spheres of radius xx.x and a bar of length xx.x with radius of x.xx is xxx.xx." Volume of sphere-4/3*pi*r3 Volume of cylinder-pi*r2*height

Explanation / Answer

clear all
clc
format short
r1=input(' enter the radius of sphere ');
r2=input(' enter the radius of cylinder ');
h=input(' enter the height of cylinder ');
v=volume(r1,r2,h);
fprintf('The volume of a barbell with two spheres of radius %5.2f ',r1);
fprintf(' and a bar of length %5.2f ',h);
fprintf(' and radius %5.2f is %5.1f',r2,v);

--------------------------------------------------------------------------------------------------------

%% function file

function [v] = volume(r1,r2,h)
volume_sphere=4/3*pi*r1^3;
volume_cylinder=pi*r2^2*h;
v=2*volume_sphere+volume_cylinder;
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote