Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Lazarus, Free Pascal, CodeTyphon
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 06.10.2010, 17:26   #1
venomdanger
Пользователь
 
Регистрация: 08.06.2010
Сообщений: 14
По умолчанию Циклы в Lazarus или в Delphi, особой разницы нет!

Здравствуйте! Нужна помощь! необходимо написать цикл с постпроверкой и цикл с предпроверкой в Lazarus или в Delphi, особой разницы нет!

Код:
unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, Grids, Spin;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    FloatSpinEdit1: TFloatSpinEdit;
    FloatSpinEdit2: TFloatSpinEdit;
    FloatSpinEdit3: TFloatSpinEdit;
    FloatSpinEdit4: TFloatSpinEdit;
    FloatSpinEdit5: TFloatSpinEdit;
    FloatSpinEdit6: TFloatSpinEdit;
    Label2: TLabel;
    Label3: TLabel;
    StringGrid1: TStringGrid;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpinEdit1Change(Sender: TObject);
    private
    { private declarations }
  public
    { public declarations }
  end; 

var
  Form1: TForm1; 

implementation

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
var
i,max:integer;
a:array[1..10]of real;
begin
for i:=1 to form1.StringGrid1.RowCount-1 do
a[i]:=StrToFloat(StringGrid1.Cells[7,i]);
     max:=1;
     for i:=1 to form1.StringGrid1.RowCount-1 do
         if a[i]> a[max]then max:=i;
     label2.caption:='Лучший результат: '+floatToStr(a[max])
                      +#13+'Номер пары: '+ IntToStr(max);
 end;

procedure TForm1.Button2Click(Sender: TObject);
begin
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
end;


procedure TForm1.Button4Click(Sender: TObject);
var
m:real;
begin
form1.StringGrid1.RowCount:=form1.StringGrid1.RowCount+1;
form1.StringGrid1.Cells[0,form1.StringGrid1.RowCount-1]:=inttostr(form1.StringGrid1.RowCount-1);
form1.StringGrid1.Cells[1,form1.StringGrid1.RowCount-1]:=floattostr(floatSpinEdit1.Value);
form1.StringGrid1.Cells[2,form1.StringGrid1.RowCount-1]:=floattostr(floatSpinEdit2.Value);
form1.StringGrid1.Cells[3,form1.StringGrid1.RowCount-1]:=floattostr(floatSpinEdit3.Value);
form1.StringGrid1.Cells[4,form1.StringGrid1.RowCount-1]:=floattostr(floatSpinEdit4.Value);
form1.StringGrid1.Cells[5,form1.StringGrid1.RowCount-1]:=floattostr(floatSpinEdit5.Value);
form1.StringGrid1.Cells[6,form1.StringGrid1.RowCount-1]:=floattostr(floatSpinEdit6.Value);
m:=floatspinEdit1.Value+floatspinEdit2.Value+floatspinEdit3.Value
+floatspinEdit4.Value+floatspinEdit5.Value+floatspinEdit6.Value;
form1.StringGrid1.Cells[7,form1.StringGrid1.RowCount-1]:=floattostr(m);
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
form1.StringGrid1.Cells[0,0]:='№';
form1.StringGrid1.Cells[1,0]:='Судья 1';
form1.StringGrid1.Cells[2,0]:='Судья 2';
form1.StringGrid1.Cells[3,0]:='Судья 3';
form1.StringGrid1.Cells[4,0]:='Судья 4';
form1.StringGrid1.Cells[5,0]:='Судья 5';
form1.StringGrid1.Cells[6,0]:='Судья 6';
form1.StringGrid1.Cells[7,0]:='Результат';
end;

procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
end;


initialization
  {$I unit1.lrs}

end.

Последний раз редактировалось venomdanger; 06.10.2010 в 17:43.
venomdanger вне форума Ответить с цитированием
Старый 06.10.2010, 17:50   #2
venomdanger
Пользователь
 
Регистрация: 08.06.2010
Сообщений: 14
По умолчанию

необходимо просто переделать эту часть кова в цикл с предпроверкой и в цикл с постпроверкой
Код:
procedure TForm1.Button1Click(Sender: TObject);
var
i,max:integer;
a:array[1..10]of real;
begin
for i:=1 to form1.StringGrid1.RowCount-1 do
a[i]:=StrToFloat(StringGrid1.Cells[7,i]);
     max:=1;
     for i:=1 to form1.StringGrid1.RowCount-1 do
         if a[i]> a[max]then max:=i;
     label2.caption:='Лучший результат: '+floatToStr(a[max])
                      +#13+'Номер пары: '+ IntToStr(max);
 end;
venomdanger вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Access+Lazarus yulia БД в Delphi 11 13.01.2016 13:53
Lazarus 666Rayne666 Помощь студентам 2 02.06.2010 17:55
Звуки в Lazarus Marsel737 Lazarus, Free Pascal, CodeTyphon 0 14.11.2009 16:37
Lazarus + Mysql DarkEvil БД в Delphi 6 18.08.2009 22:18