線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:643
推到 Plurk!
推到 Facebook!

關於各科平均的程式碼該放在那....

尚未結案
gigitahoo
一般會員


發表:8
回覆:2
積分:2
註冊:2004-09-16

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-10-24 00:56:33 IP:218.163.xxx.xxx 未訂閱
各位前輩您們好: 若我想在加人各科的平均,不知我下面的語法是錯在那呢?? 還是我加錯地方了.因為都SHOW不出來..程式碼如下.. 在麻煩各位前輩幫忙解答!感激... ============================================================== //計算各科平均 for k:=1 to z do begin a[4].chi:=a[4].chi a[k].chi; a[4].eng:=a[4].eng a[k].eng; a[4].math:=a[4].math a[k].math; a[4].sdiv:=a[4].sdiv a[k].sdiv; end; a[4].chi:=a[4].chi div 3; a[4].eng:=a[4].eng div 3; a[4].math:=a[4].math div 3; a[4].sdiv:=a[4].sdiv div 3; ============================================================= unit recordtest; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids; type TForm1 = class(TForm) StringGrid1: TStringGrid; Button1: TButton; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type Tstud=record no:string; name:string; chi:integer; eng:integer; math:integer; sdiv:integer; size:integer; memo:string; end; var Form1: TForm1; a:array[0..8] of Tstud; z:integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var i,j:integer; begin button1.Caption:='計算'; button2.Caption:='結束'; z:=strtoint(inputbox('輸入學生人數','請輸入','3')); for i:=1 to z do begin a[i].no:=inttostr(i); a[i].name:=inputbox('輸入姓名','輸入第' inttostr(i) '位姓名',' '); a[i].chi:=strtoint(inputbox('輸入國文成績','輸入第' inttostr(i) '位成績','')); a[i].eng:=strtoint(inputbox('輸入英文成績','輸入第' inttostr(i) '位成績','')); a[i].math:=strtoint(inputbox('輸入數學成績','輸入第' inttostr(i) '位成績','')); end; with stringgrid1 do begin colcount:=8; rowcount:=z 1; cells[0,0]:='座號'; cells[1,0]:='姓名'; cells[2,0]:='國文'; cells[3,0]:='英文'; cells[4,0]:='數學'; cells[5,0]:='平均'; cells[6,0]:='名次'; cells[7,0]:='註記'; end; for j:=1 to z do begin stringgrid1.Cells[0,j]:=a[j].no; stringgrid1.Cells[1,j]:=a[j].name; stringgrid1.Cells[2,j]:=inttostr(a[j].chi); stringgrid1.Cells[3,j]:=inttostr(a[j].eng); stringgrid1.Cells[4,j]:=inttostr(a[j].math); end; end; procedure TForm1.Button1Click(Sender: TObject); var i,j:integer; begin //平均&註記 for i:=1 to z do begin a[i].sdiv:= (a[i].chi a[i].eng a[i].math) div 3; stringgrid1.cells[5,i]:=inttostr(a[i].sdiv); if a[i].sdiv < 60 then begin stringgrid1.Cells[7,i]:='當掉'; end; end; //計數排名 for i:=1 to z do begin a[i].size:=1; stringgrid1.cells[6,i]:=inttostr(a[i].size); end; for i:=1 to z do begin for j:=i 1 to z do begin if a[i].sdiv > a[j].sdiv then begin a[j].size:=a[j].size 1; stringgrid1.Cells[6,j]:=inttostr(a[j].size); end else begin a[i].size:=a[i].size 1; stringgrid1.Cells[6,i]:=inttostr(a[i].size); end; end; end; end; procedure TForm1.Button2Click(Sender: TObject); begin close; end; end. =================================================
ddy
站務副站長


發表:262
回覆:2105
積分:1169
註冊:2002-07-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-10-24 01:08:30 IP:61.62.xxx.xxx 未訂閱
程式碼未縮排,可讀性低,予以刪除!!    
系統時間:2024-06-16 5:06:15
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!