unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, DateTimePicker, Forms, Controls, Graphics, Dialogs, StdCtrls, Grids, ExtDlgs, EditBtn; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; Button4: TButton; Button5: TButton; Button6: TButton; DateEdit1: TDateEdit; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Edit4: TEdit; Edit5: TEdit; Edit6: TEdit; Edit7: TEdit; Edit8: TEdit; GroupBox1: TGroupBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; RadioButton1: TRadioButton; RadioButton2: TRadioButton; StrSpusok: TStringGrid; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure DeleteRow(ARow: Integer); private { private declarations } public { public declarations } end; //оголошення запису учня student = record prizv, name,data : string; //дані про учня estimation : array [ 1.. 5 ] of integer; //оцінки s_ball : real; //середній бал end; var Form1: TForm1; //масив змінних типу "учень" x : array [ 0.. 50 ] of student; //змінна для підрахунку кількості учнів i : integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.DeleteRow(ARow: Integer); var i, j: Integer; begin with StrSpusok do begin for i:=ARow+1 to RowCount-1 do for j:=0 to ColCount-1 do Cells[j, i-1]:=Cells[j, i]; RowCount:=RowCount-1; end; end; procedure TForm1.FormCreate(Sender: TObject); begin i:=0; //кількість учнів спочатку дорівнює 0 end; procedure TForm1.Button1Click(Sender: TObject); // Зберегти дані var sum,j: integer; begin //читання даних з форми x[i].Prizv := Edit1. Text; x[i].name:= Edit2. Text; x[i].data:=DateEdit1.Text; x[i].estimation[1]:= strToInt ( Edit4. Text ); x[i].estimation[2]:= strToInt ( Edit5. Text ); x[i].estimation[3]:= strToInt ( Edit6. Text ); x[i].estimation[4]:= strToInt ( Edit7. Text ); x[i].estimation[5]:= strToInt ( Edit8. Text ); //підрахунок середнього балу sum:= 0; for j:=1 to 5 do sum:=sum +x[i]. estimation[j]; x[i].s_ball:=sum / 5; inc(i); //очищення полів ввода для наступних даних Edit1.Clear;Edit2.Clear;Edit4.Clear; Edit5.Clear;Edit6.Clear;Edit7.Clear;Edit8.Clear; end; procedure TForm1.Button2Click(Sender: TObject); // вивести дані var f : textfile; j : integer; s : string; begin //кількість рядків в таблиці StringGrid буде на 1 більше, //ніж кількістьучнів (плюс 1 рядок для шапки) StrSpusok.RowCount:= i +1; //вивід шапки таблиці StrSpusok.Cells[0,0]:='№ п/п'; StrSpusok.Cells [ 1, 0 ]:= 'Прізвище'; StrSpusok.Cells [ 2, 0 ]:= 'Ім''я'; StrSpusok.Cells [ 3, 0 ]:= 'Дата народж. '; StrSpusok.Cells [ 4, 0 ]:= 'Середній бал'; //вивід відомостей про учнів в j-й рядок for j :=1 to i do begin StrSpusok.Cells[ 0, j ]:= IntToStr(j); StrSpusok.Cells[ 1, j ]:= x [ j - 1 ]. prizv; StrSpusok.Cells[ 2, j ]:= x [ j - 1 ]. name; StrSpusok.Cells[ 3, j ]:= x [ j - 1 ]. data; StrSpusok.Cells[ 4, j ]:= floattostr ( x [ j - 1 ]. s_ball ); end; //вивід результатів в текстовий файл AssignFile(f, 'student.txt'); Rewrite(f); for j :=1 to i do begin writeln ( f, j,x [j - 1].prizv : 20, x [j - 1].name : 15, x [j - 1].data : 15, ' Sr_ball= ', x [j - 1].s_ball : 4 : 1 ); end; closefile ( f ); end; procedure TForm1.Button3Click(Sender: TObject); // Видалити запис var st:integer; begin st:=StrSpusok.Row; DeleteRow(st); end; procedure TForm1.Button4Click(Sender: TObject); // впорядкування var j, k : integer; temp : student; //тимчасова змінна для сортування begin for j := 0 to i -1 do for k:= j +1 to i -1 do if x [ j ].prizv > x [ k ]. prizv then begin temp:=x [ j ]; x [ j ]:= x [ k ]; x [ k ]:= temp; end; end; procedure TForm1.Button5Click(Sender: TObject); begin Close;// Вихід з програми end; procedure TForm1.Button6Click(Sender: TObject); //пошук var i,j:integer; f:boolean; begin f:=false; if RadioButton1.Checked then begin for i:=1 to StrSpusok.RowCount -1 do if StrSpusok.Cells[1,i]=edit3.Text then begin StrSpusok.Row:=i;f:=true;end else f:=false; end else begin for i:=1 to StrSpusok.RowCount -1 do if StrSpusok.Cells[4,i]=edit3.Text then begin StrSpusok.Row:=i; f:=true;end else f:=false; end end; end.