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

In a function file named getCylinderinfo.m, write a user-defined function named

ID: 2082345 • Letter: I

Question

In a function file named getCylinderinfo.m, write a user-defined function named getcylinderInfo() that prompts the user for the height and radius of a right circular cylinder. The user should be continuously prompted until the user enters a non-negative radius and a non-negative height, respectively. User-defined function getCylinderInfo() does not accept any input parameters but returns two output parameters named heighOut and radiusOut, respectively. Output parameter heightOut represents the height of the circular cylinder while output parameter radiusOut represents the radius of the top and bottom parts of the circular cylinder.

Explanation / Answer

Function file

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

function [heightout, radiusOut] = GetCylinderInfo()
height = input('Height of a circle: ');
radius = input('Radius of a circle: ');
while(radius < 0) | (height < 0)
fprintf('Invalid input. Enter again! ');
height = input('Height of a circle: ');
radius = input('Radius of a circle: ');
end
heightout = height;
radiusOut = radius;

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

Script File

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

clc;
[height, radius] = GetCylinderInfo();
fprintf('The height is %d and the radius is %d ' ,height, radius);

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

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