Created
May 5, 2016 12:34
-
-
Save yfhust/7304d652c64e71797bd17743250bc33b to your computer and use it in GitHub Desktop.
Programs for Fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = parseFloat(getUserInputValue("请输入土方下底面的长度", 100)); | |
b = parseFloat(getUserInputValue("请输入土方下底面的宽度", 100)); | |
x = parseFloat(getUserInputValue("请输入土方上底面的长度", 100)); | |
y = parseFloat(getUserInputValue("请输入土方上底面的宽度", 100)); | |
h = parseFloat(getUserInputValue("请输入土方的高度", 10)); | |
totalArea = eachArea(a,b,x,y,h)+eachArea(b,a,y,x,h); | |
print("短梯形的高是: "+sqrt((square((b-y)/2)) + square(h))); | |
print("长梯形的高是: "+sqrt((square((a-x)/2)) + square(h))); | |
print("每个短梯形的面积是: "+(eachArea(a,b,x,y,h))/2); | |
print("每个长梯形的面积是: "+(eachArea(b,a,y,x,h))/2); | |
print("四个侧面梯形的面积总和是: "+totalArea); | |
function square(x){ | |
return x*x; | |
} | |
function eachArea(a,b,x,y,h){ | |
return (a+x)*sqrt((square((b-y)/2)) + square(h)); | |
} | |
function getUserInputValue(dialogueTitle, defaultValue){ | |
Dialog.create(dialogueTitle); | |
Dialog.addNumber(dialogueTitle+": ", defaultValue, 2, 8, "米"); //对话框标题,默认值,小数位数,输入框宽度,输入框右侧单位 | |
Dialog.show(); | |
return Dialog.getNumber(); //将输入的数值赋给变量 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment