你好。。。能否帮我看看这道题呢?非常感谢
展开全部
clc
clear all
n=0;
while 1
n=n+1;
fprintf('Cylinder #%d\n',n)
[heightOut,radiusOut]=getCylinderInfo;
[surfAreaOut,VolOut]=calcAreaAndVolume(heightOut,radiusOut);
dispAreaAndVolume(surfAreaOut,VolOut)
Str=input('Calculate info for another cyclinder?[Y/y]es [N/n]o:\n','s');
if(Str=='N'||Str=='n')
break;
else
continue;
end
end
function [heightOut,radiusOut]=getCylinderInfo
hr(1)=-1;hr(2)=-1;
while(hr(1)<0||hr(2)<0)
hr=input('Please Insert height and radius of the circular cylinder:\n');
end
if(hr(1)>=0&&hr(2)>=0)
fprintf('Successfully data saved!\n')
heightOut=hr(1);radiusOut=hr(2);
else
fprintf('Non-negative number should be applied!')
end
end
function [surfAreaOut,VolOut]=calcAreaAndVolume(heightIn,radiusIn)
surfAreaOut=2*pi*radiusIn*heightIn+2*pi*radiusIn^2;
VolOut=pi*radiusIn^2*heightIn;
end
function dispAreaAndVolume(surfAreaIn,VolIn)
fprintf('surfArea=%f\nVolume=%f\n',surfAreaIn,VolIn)
end
clear all
n=0;
while 1
n=n+1;
fprintf('Cylinder #%d\n',n)
[heightOut,radiusOut]=getCylinderInfo;
[surfAreaOut,VolOut]=calcAreaAndVolume(heightOut,radiusOut);
dispAreaAndVolume(surfAreaOut,VolOut)
Str=input('Calculate info for another cyclinder?[Y/y]es [N/n]o:\n','s');
if(Str=='N'||Str=='n')
break;
else
continue;
end
end
function [heightOut,radiusOut]=getCylinderInfo
hr(1)=-1;hr(2)=-1;
while(hr(1)<0||hr(2)<0)
hr=input('Please Insert height and radius of the circular cylinder:\n');
end
if(hr(1)>=0&&hr(2)>=0)
fprintf('Successfully data saved!\n')
heightOut=hr(1);radiusOut=hr(2);
else
fprintf('Non-negative number should be applied!')
end
end
function [surfAreaOut,VolOut]=calcAreaAndVolume(heightIn,radiusIn)
surfAreaOut=2*pi*radiusIn*heightIn+2*pi*radiusIn^2;
VolOut=pi*radiusIn^2*heightIn;
end
function dispAreaAndVolume(surfAreaIn,VolIn)
fprintf('surfArea=%f\nVolume=%f\n',surfAreaIn,VolIn)
end
追答
看清楚三个函数的代码分界点,function开头的,百度没提供代码的粘贴功能,噢
明天我把文档发给你吧,现在寝室停电了
来自:求助得到的回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询