|
|
Регистрация Восстановить пароль |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
|
Опции темы | Поиск в этой теме |
20.03.2013, 21:34 | #1 |
Пользователь
Регистрация: 22.02.2013
Сообщений: 47
|
Компоненты Delphi
Помогите пожалуйста, с задачей "Принятие решений в условиях риска"
Вот код: procedure TForm2.FormCreate(Sender: TObject); begin form2.Label1.Visible:=false; form2.StringGrid1.Cells[0,0]:='Ai/Bj'; form2.StringGrid1.Cells[0,1]:='A1'; form2.StringGrid1.Cells[0,2]:='A2'; form2.StringGrid1.Cells[0,3]:='A3'; form2.StringGrid1.Cells[0,4]:='x'; form2.StringGrid1.Cells[1,0]:='B1'; form2.StringGrid1.Cells[2,0]:='B2'; form2.StringGrid1.Cells[3,0]:='B3'; form2.StringGrid2.Cells[0,0]:='Ai/Bj'; form2.StringGrid2.Cells[0,1]:='A1'; form2.StringGrid2.Cells[0,2]:='A2'; form2.StringGrid2.Cells[0,3]:='A3'; form2.StringGrid2.Cells[4,0]:='R'; form2.StringGrid2.Cells[1,0]:='B1'; form2.StringGrid2.Cells[2,0]:='B2'; form2.StringGrid2.Cells[3,0]:='B3'; end; procedure TForm2.Button1Click(Sender: TObject); var a,b,i,max,min: integer; a1,a2,a3,k,u:real; R1,R2,R3,d:string; p,o: real; pusto: bool; begin pusto:= true; for a:= 1 to StringGrid1.ColCount-1 do for b:= 1 to StringGrid1.RowCount-1 do if StringGrid1.Cells[a,b] <> '' then pusto:= false; if pusto then begin application.MessageBox('Заполни таблицу','Внимание'); end else begin if combobox1.ItemIndex=-1 then application.MessageBox('Выбирете что-нибудь','Внимание');; if combobox1.ItemIndex=0 then begin for a:=1 to 3 do begin stringgrid2.Cells[1,a]:=inttostr(strtoint(stringgrid1.Cel ls[1,a])*strtoint(stringgrid1.Cells[1,4])); stringgrid2.Cells[2,a]:=inttostr(strtoint(stringgrid1.Cel ls[2,a])*strtoint(stringgrid1.Cells[2,4])); stringgrid2.Cells[3,a]:=inttostr(strtoint(stringgrid1.Cel ls[3,a])*strtoint(stringgrid1.Cells[3,4])); end; R1:=stringgrid2.Cells[1,1]; R2:=stringgrid2.Cells[1,2]; R3:=stringgrid2.Cells[1,3]; for i:=1 to 3 do begin if strtoint(R1)<strtoint(stringgrid2.C ells[i,1]) then R1:=stringgrid2.Cells[i,1]; if strtoint(R2)<strtoint(stringgrid2.C ells[i,2]) then R2:=stringgrid2.Cells[i,2]; if strtoint(R3)<strtoint(stringgrid2.C ells[i,3]) then R3:=stringgrid2.Cells[i,3]; if strtoint(R1)>=strtoint(R2) then begin max:=strtoint(R1); d:='(A1)'; end else begin max:=strtoint(R2); d:='(A2)'; end; if max>=strtoint(R3) then begin end else begin max:=strtoint(R3); d:='(A3)'; end; end; stringgrid2.Cells[4,1]:=R1; stringgrid2.Cells[4,2]:=R2; stringgrid2.Cells[4,3]:=R3; label1.Caption:='Наиболее прибыльное значение = '+inttostr(max)+d; form2.Label1.Visible:=true; end; if combobox1.ItemIndex=1 then begin for a:=1 to 3 do begin stringgrid2.Cells[1,a]:=inttostr(strtoint(stringgrid1.Cel ls[1,a])*strtoint(stringgrid1.Cells[1,4])); stringgrid2.Cells[2,a]:=inttostr(strtoint(stringgrid1.Cel ls[2,a])*strtoint(stringgrid1.Cells[2,4])); stringgrid2.Cells[3,a]:=inttostr(strtoint(stringgrid1.Cel ls[3,a])*strtoint(stringgrid1.Cells[3,4])); end; R1:=stringgrid2.Cells[1,1]; R2:=stringgrid2.Cells[1,2]; R3:=stringgrid2.Cells[1,3]; for i:=1 to 3 do begin if strtoint(R1)<strtoint(stringgrid2.C ells[i,1]) then R1:=stringgrid2.Cells[i,1]; if strtoint(R2)<strtoint(stringgrid2.C ells[i,2]) then R2:=stringgrid2.Cells[i,2]; if strtoint(R3)<strtoint(stringgrid2.C ells[i,3]) then R3:=stringgrid2.Cells[i,3]; if strtoint(R1)<=strtoint(R2) then begin min:=strtoint(R1); d:='(A1)'; end else begin min:=strtoint(R2); d:='(A2)'; end; if min<=strtoint(R3) then begin end else begin min:=strtoint(R3); d:='(A3)'; end; end; stringgrid2.Cells[4,1]:=R1; stringgrid2.Cells[4,2]:=R2; stringgrid2.Cells[4,3]:=R3; label1.Caption:='Наименее рискованное значение = '+inttostr(min)+d; form2.Label1.Visible:=true; end; end; end; |
20.03.2013, 21:35 | #2 |
Пользователь
Регистрация: 22.02.2013
Сообщений: 47
|
ПРОДОЛЖЕНИЕ...
procedure TForm2.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if gdSelected in State then with TStringGrid(Sender), TStringGrid(Sender).Canvas do begin Brush.Color:=clwhite; FillRect(Rect); TextRect(Rect, Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]); end; end; procedure TForm2.StringGrid2DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); begin if gdSelected in State then with TStringGrid(Sender), TStringGrid(Sender).Canvas do begin Brush.Color:=clscrollbar; FillRect(Rect); TextRect(Rect, Rect.Left+2, Rect.Top+2, Cells[ACol, ARow]); end; end; procedure TForm2.StringGrid1KeyPress(Sender: TObject; var Key: Char); var vrPos, vrLength, vrSelStart:Byte; const w:Byte=1; begin with Sender as TStringGrid do begin vrLength := Length(Text); //определяем длину текста vrPos := Pos(',', Text); //проверяем наличие запятой end; case Key of '0'..'9': begin //проверяем положение курсора и количество знаков после запятой if (vrPos > 0) and (vrLength - vrPos > w) then Key := #0; //"погасить" клавишу end; ',', '.': begin //если запятая уже есть или запятую пытаются поставить перед //числом или никаких цифр в поле ввода еще нет if (vrPos > 0) or (vrLength = 0) then Key := #0 //"погасить" клавишу end; #8: ; //позволить удаление знаков клавишей 'Back Space' else Key := #0; //"погасить" все остальные клавиши end; end; procedure TForm2.Button2Click(Sender: TObject); begin close end; procedure TForm2.Button3Click(Sender: TObject); Var i,j: integer; begin for i := 1 to StringGrid1.ColCount-1 do for j := 1 to StringGrid1.RowCount-1 do StringGrid1.Cells[i,j] := ''; for i := 1 to StringGrid2.ColCount-1 do for j := 1 to StringGrid2.RowCount-1 do StringGrid2.Cells[i,j] := ''; end; end. Задача решается только с целыми числами, но в первом StringGrid мне надо задать вероятность, как только я ввожу десятичные числа у меня выдаёт ошибку. Помогите пожалуйста с кодом |
21.03.2013, 09:23 | #3 |
Старожил
Регистрация: 20.04.2008
Сообщений: 5,528
|
Код:
программа — запись алгоритма на языке понятном транслятору
|
21.03.2013, 14:09 | #4 |
Пользователь
Регистрация: 22.02.2013
Сообщений: 47
|
А куда это поместить в самом коде?
|
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
графич. компоненты Delphi | detalik | Помощь студентам | 7 | 18.04.2011 16:32 |
Компоненты delphi | mihali4 | Компоненты Delphi | 0 | 22.10.2010 23:04 |
Компоненты в Delphi. | Chudo4258 | Помощь студентам | 4 | 21.03.2009 18:53 |
Excel и компоненты Delphi | monushka | Помощь студентам | 4 | 26.01.2008 17:51 |
Компоненты Delphi | netuser | Общие вопросы Delphi | 7 | 29.06.2007 08:49 |