全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1137
推到 Plurk!
推到 Facebook!

是算法还是函数?数组?

答題得分者是:jow
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-12-05 15:19:06 IP:125.215.xxx.xxx 訂閱
如果我要实现下面的功能,要用到什么知识啊?数组?还是集合?
1-10:取值为5;
11-20:取值为10;
21-40:取值为20;
40以上:取值为40
。。。。。
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
cobraliu
中階會員


發表:15
回覆:75
積分:83
註冊:2007-11-22

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-12-05 18:00:47 IP:59.127.xxx.xxx 訂閱
拉了兩個edit1,edit2跟一個button 在button中寫了這一段不知這是不是有符合你的需求   case strtoint(edit1.Text) of
1..10:
edit2.Text := inttostr(5);
11..20:
edit2.Text := inttostr(10);
21..40:
edit2.Text := inttostr(20);
ELSE
IF strtoint(edit1.Text) > 40 THEN
edit2.Text := inttostr(40);
END;
------
初學、初學、學了很久...還是在初學階段..Orz
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-12-07 12:29:10 IP:210.66.xxx.xxx 訂閱
我的建議: 試著把它寫成函式, 如何?
讓數值的得取動作與結果的顯示分開...

===================引 用 cobraliu 文 章===================
拉了兩個edit1,edit2跟一個button 在button中寫了這一段不知這是不是有符合你的需求 case strtoint(edit1.Text) of
1..10:
edit2.Text := inttostr(5);
11..20:
edit2.Text := inttostr(10);
21..40:
edit2.Text := inttostr(20);
ELSE
IF strtoint(edit1.Text) > 40 THEN
edit2.Text := inttostr(40);
END;
編輯記錄
jow 重新編輯於 2007-12-07 12:30:00, 註解 無‧
zhouying82
高階會員


發表:150
回覆:272
積分:189
註冊:2004-03-16

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-12-09 14:34:57 IP:222.64.xxx.xxx 訂閱
jow,你是否可以提供相关的源码?
------
断断续续的学了几年,还是一个初学者,永远支持Delphi !
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-12-10 00:34:13 IP:123.193.xxx.xxx 訂閱
記得要處理未定義的輸入範圍....
[code delphi]
function TForm1.GetValue0(V: Integer; var ret: Integer): Boolean;
begin
if V < 1 then ret := -1
else if V <= 10 then ret := 5
else if V <= 20 then ret := 10
else if V <= 40 then ret := 20
else ret := 40;
Result := ret <> -1;
end;

function TForm1.GetValue1(V: Integer; var ret: Integer): Boolean;
begin
ret := -1;
case V of
01..10: ret := 5;
11..20: ret := 10;
21..40: ret := 20;
else if V > 40 then ret := 40;
end;
Result := ret <> -1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
Edit1.Text := '範圍未定義!';
Edit2.Text := '範圍未定義!';
if GetValue0(Random(50), I) then Edit1.Text := IntToStr(I);
if GetValue1(Random(50), I) then Edit2.Text := IntToStr(I);
end;

[/code]
===================引 用 zhouying82 文 章===================
jow,你是否可以提供相关的源码?
編輯記錄
jow 重新編輯於 2007-12-10 00:39:21, 註解 無‧
系統時間:2024-04-25 20:55:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!