Two-dimensional array
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls, dbctrls; Type queue = array [1 .. 4, 1 .. 20] of real; tform1 = Class (tform) lbl1: tlabel; lbl2: tlabel; lbl3: tlabel; lbl4: tlabel; lbl5: tlabel; btn1: tbutton; edt1: tedit; edt2: tedit; edt3: tedit; edt4: tedit; Metadata: tdblistbox; lbl6: tlabel; btn2: tbutton; btn3: tbutton; labresult: tlabel; Procedure btn2click (Sender: tobject ); procedure btn1click (Sender: tobject); Private {private Declarations} public function AVG (queue1: queue; M, N: integer): real; {public declarations} end; var form1: tform1; I: integer; score: queue; implementation {$ R *. DFM} function tform1.avg (queue1: queue; M, N: integer): real; var K: integer; sum: real; begin sum: = 0; for K: = 1 to n do sum: = sum + queue1 [m] [k]; Result: = sum/N; end; Procedure tform1.btn2click (Sender: tobject); var engave, mathave, vfpave, dataave: real; // The average score of each of the four courses, respectively. Begin engave: = AVG (score, 1, I); // call the function aver, calculate the average score of an I student in English. mathave: = AVG (score, 2, I); // call the function aver to obtain the average score of an I student in mathematics. vfpave: = AVG (score, 3, I); // call the aver function to calculate the average value of the VFP score of I students. dataave: = AVG (score, 4, I ); // call the function aver to calculate the average value of the I student data structure. // The calculation result is displayed as labresult. caption: = 'average score of each subject: '+ CHR (13) + CHR (13); labresult. caption: = labresult. caption + 'English: '+ floattostr (engave); labresult. caption: = labresult. caption + ';' + 'mathematics:' + floattostr (mathave); labresult. caption: = labresult. caption + ';' + 'vfp: '+ floattostr (vfpave); labresult. caption: = labresult. caption + ';' + 'Data Structure:' + floattostr (dataave); end; Procedure tform1.btn1click (Sender: tobject); var str1: string; begin I: = I + 1; // Add 1 score for each input student information [1] [I]: = strtofloat (edt1.text ); // The first row of the score array stores the score in English [2] [I]: = strtofloat (edt2.text ); // The first row of the score array stores the score [3] [I]: = strtofloat (edt3.text ); // The second row of the score array stores the VFP score [4] [I]: = strtofloat (edt4.text); // the data structure of the second row of the score array is str1: = edt1.text + ''+ edt2.text +'' + edt3.text + ''+ edt4.text; dblst1.items. add (str1); // Add the scores of students I TO THE scorelist list edt1.text: = ''; // clear the text boxes edt2.text: = ''; edt3.text: =''; edt4.text: = ''; edt1.setfocus; // The cursor is positioned in the engedit text box, waiting for the next input end; end.