НА ДЕЛФИ(показывает ошибку). С нулевым значением
С нулевым значением
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; StringGrid1: TStringGrid; Button1: TButton; Button2: TButton; Memo1: TMemo; Button3: TButton; procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button3Click(Sender: TObject); begin Form1.Close; end; procedure TForm1.Button1Click(Sender: TObject); const s=5; var a:array[1..s] of integer; i,imax,max:integer; begin for i:=1 to s do a[i]:=Strtoint(StringGrid1.Cells[i-1,0]); for i:=1 to s do begin if (a[i] mod 2=0) then begin imax:=i; max:=a[i]; break; end;end; for i:=1 to s do begin if (a[i] mod 2=0) then begin if (a[i]>max) then begin max:=a[i]; imax:=i; end; end; end; Memo1.Lines.Add('номер эл-та, имеющего максим. Четное зн-ние ='+IntToStr(imax)); Memo1.Lines.Add('его зн-ние='+IntToStr(max)); end; procedure TForm1.Button2Click(Sender: TObject); const s=5; var a:array[1..s] of integer; i,i1,i2,proiz:integer; begin proiz:=1; i1:=0; i2:=0; for i:=1 to s do a[i]:=StrToInt(StringGrid1.Cells[i-1,0]); for i:=1 to s do begin if (a[i]=0) then begin i1:=i; break; end; end; for i:=i1+1 to s do begin if (a[i]=0) then begin i2:=i; break; end; end; Memo1.Lines.Add('номер 1ого и 2ого нулевых эл-тов='+intToStr(i1)+' '+ intToStr(i2)); for i:=i1+1 to i2-1 do proiz:=proiz*a[i]; Memo1.Lines.Add('Произвед. Эл-тов между ними='+IntToStr(proiz)); end; end.
Без учета нуля
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; StringGrid1: TStringGrid; Button1: TButton; Button2: TButton; Memo1: TMemo; Button3: TButton; procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button3Click(Sender: TObject); begin Form1.Close; end; procedure TForm1.Button1Click(Sender: TObject); const s=5; var a:array[1..s] of integer; i,imax,max:integer; begin for i:=1 to s do a[i]:=Strtoint(StringGrid1.Cells[i-1,0]); for i:=1 to s do begin if (a[i]<>0) then begin if (a[i] mod 2=0) then begin imax:=i; max:=a[i]; break; end;end;end; for i:=1 to s do begin if (a[i]<>0) then begin if (a[i] mod 2=0) then begin if (a[i]>max) then begin max:=a[i]; imax:=i; end;end;end;end; Memo1.Lines.Add('номер эл-та, имеющего максим. Четное зн-ние ='+IntToStr(imax)); Memo1.Lines.Add('его зн-ние ='+IntToStr(max)); end; procedure TForm1.Button2Click(Sender: TObject); const s=5; var a:array[1..s] of integer; i,i1,i2,proiz:integer; begin proiz:=1; i1:=0; i2:=0; for i:=1 to s do a[i]:=StrToInt(StringGrid1.Cells[i-1,0]); for i:=1 to s do begin if (a[i]=0) then begin i1:=i; break; end;end; for i:=i1+1 to s do begin if (a[i]=0) then begin i2:=i; break; end; end; Memo1.Lines.Add('номер 1ого и 2ого нулевых эл-тов ='+intToStr(i1)+' '+ intToStr(i2)); for i:=i1+1 to i2-1 do proiz:=proiz*a[i]; Memo1.Lines.Add('Произвед. Эл-тов между ними ='+IntToStr(proiz)); end;end.
НА С++ БЕЗ УЧЕТА НУЛЯ #include <vcl.h> #pragma hdrstop #include "Unit1.h" #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){} void __fastcall TForm1::Button3Click(TObject *Sender) {Form1->Close();} //--------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) {const s=5; int a[s]; int i,imax,max; for (i=1; i<=s;i++){ a[i]=StrToInt(StringGrid1->Cells[i-1][0]); } for (i=1;i<=s;i++) {if (a[i]!=0){ if (a[i]%2==0) {max=a[i]; imax=i; break;}}} for (i=1; i<=s;i++) {if (a[i]!=0) {if (a[i]%2==0) {if (a[i]>max) {max=a[i]; imax=i; }}}} Memo1->Lines->Add("номер элемента массива,имеющего макс. четное зн-ние="+IntToStr(imax));} //--------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) {const s=5; int a[s]; int i,i1,i2,proiz; proiz=1; for (i=1; i<=s;i++) {a[i]=StrToInt(StringGrid1->Cells[i-1][0]);} for (i=1; i<=s;i++) {if (a[i]==0){ i1=i; break;}} for (i=i1+1; i<=s; i++) {if (a[i]==0) {i2=i; break;}} for (i=i1+1; i<i2; i++) {proiz=proiz*a[i]; }Memo1->Lines->Add("Номера 1ого и 2ого нулевых элементов="+IntToStr(i1)+" и "+IntToStr(i2)); Memo1->Lines->Add("произведение="+IntToStr(proiz));} //---------------------------------------------------------------
С УЧЕТОМ НУЛЯ
#include <vcl.h> #pragma hdrstop #include "Unit1.h" #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){} //--------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) {Form1->Close();} //--------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) {const s=5; int a[s]; int i,imax,max; for (i=1; i<=s;i++){ a[i]=StrToInt(StringGrid1->Cells[i-1][0]); }for (i=1;i<=s;i++) {if (a[i]%2==0) {max=a[i]; imax=i; break;}} for (i=1; i<=s;i++) {if (a[i]%2==0){ if (a[i]>max) {max=a[i]; imax=i;}}} Memo1->Lines->Add("номер элемента массива,имеющего макс. четное зн-ние="+IntToStr(imax));} //--------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) {const s=5; int a[s]; int i,i1,i2,proiz; proiz=1; for (i=1; i<=s;i++){ a[i]=StrToInt(StringGrid1->Cells[i-1][0]); }for (i=1; i<=s;i++) {if (a[i]==0) {i1=i; break;}} for (i=i1+1; i<=s; i++) {if (a[i]==0) {i2=i; break;}} for (i=i1+1; i<i2; i++){ proiz=proiz*a[i]; }Memo1->Lines->Add("Номера 1ого и 2ого нулевых элементов="+IntToStr(i1)+" и "+IntToStr(i2)); Memo1->Lines->Add("произведение="+IntToStr(proiz));} //---------------------------------------------------------------
Задача 15. Для десяти выстрелов, координаты которых задаются с клавиатуры, вывести текстовые сообщения о попадании в мишень, определенной заштрихованной областью. НА ДЕЛФИ unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Button1: TButton; Memo1: TMemo; Label3: TLabel; Edit3: TEdit; Button2: TButton; Button3: TButton; Label4: TLabel; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var x,y,r:real; begin x:=strtofloat(edit1.Text); y:=strtofloat(edit2.Text); r:=strtofloat(edit3.Text); begin if (x>0)and (y>0) and (y>=x) and(x<=r) and(y<=r) then Memo1.Lines.Add('В яблочко!') else if (x<0)and (y<0) and (y>=x) and(x>=-r) and(y>=-r) then Memo1.Lines.Add('В яблочко ') else Memo1.Lines.Add('Промох!'); end;end; procedure TForm1.Button3Click(Sender: TObject); begin Close; end; procedure TForm1.Button2Click(Sender: TObject); begin Edit1.Text:=''; Edit2.Text:=''; Edit3.Text:=''; end; end.
НА С++ #include <vcl.h> #pragma hdrstop #include "Unit1.h" #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){} //--------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender) {Form1->Close();} //---------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender) {Edit1->Text=" "; Edit2->Text=" "; Edit3->Text=" ";} //--------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) {float x,y,r; x=StrToFloat(Edit1->Text); y=StrToFloat(Edit2->Text); r=StrToFloat(Edit3->Text); if ((x>0)&&(y>0)&&(y>=x)&&(x<=r)&&(y<=r)) Memo1->Lines->Add("В Яблочко!"); else if ((x<0)&&(y<0)&&(y>=x)&&(x>=-r)&&(y>=-r)) Memo1->Lines->Add("В Яблочко!"); else Memo1->Lines->Add("Промах!");} //---------------------------------------------------------------
Задача 16. Для десяти выстрелов, координаты которых задаются с клавиатуры, вывести текстовые сообщения о попадании в мишень, определенной заштрихованной областью.
НА ДЕЛФИ
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Label2: TLabel; Edit2: TEdit; Label3: TLabel; Edit3: TEdit; Button1: TButton; Memo1: TMemo; Button2: TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button2Click(Sender: TObject); begin Form1.Close; end; procedure TForm1.Button1Click(Sender: TObject); var x,y,r:real; begin x:=strtofloat(Edit1.Text); y:=strtofloat(Edit2.Text); r:=strtofloat(Edit3.Text); if ((x>=0) and (y>=0) and (x<=r) and (y<=r)) then Memo1.Lines.Add('Попал!') else if ((x<=0) and (x>=-r) and (y<=0) and (y>=-r)) then Memo1.Lines.Add('Попал!') else if ((sqr(x+r)+sqr(y-r))<=sqr(r)) then Memo1.Lines.Add('не попал!') else if ((sqr(x-r)+sqr(y+r))<=sqr(r)) then Memo1.Lines.Add('не попал!') else if (x>r) and (x<-r) and (y>r) and (y<-r) then Memo1.Lines.Add('не попал!') else if ((x>r) and (y>r)) then Memo1.Lines.Add('не попал!') else if ((x<-r) and (y<-r)) then Memo1.Lines.Add('не попал!') else if ((sqr(x+r)+sqr(y-r))>sqr(r)) then Memo1.Lines.Add('не попал!') else if ((sqr(x-r)+sqr(y+r))>sqr(r)) then Memo1.Lines.Add('не попал!') else Memo1.Lines.Add('ïîïàë!')
end;
end. Задача 17. В одномерном массиве, состоящем из целочисленных элементов, вычислить: · количество элементов массива, больших С; · произведение элементов массива, расположенных после максимального по модулю элемента. НА ДЕЛФИ(показывает ошибку) unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls, ComCtrls; type TForm1 = class(TForm) StringGrid1: TStringGrid; Button1: TButton; Edit1: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; UpDown1: TUpDown; Edit2: TEdit; Label7: TLabel; Label8: TLabel; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure UpDown1Click(Sender: TObject; Button: TUDBtnType); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var i,j,k,m:integer; begin k:=0; for i:=0 to StringGrid1.ColCount-1 do if StrToInt(StringGrid1.Cells[i,0])>StrToInt(Edit1.Text) then inc(k); Label2.Caption:=IntToStr(k); k:=0; m:=0; for i:=0 to StringGrid1.ColCount-1 do if Abs(StrToInt(StringGrid1.Cells[i,0]))>m then begin m:=Abs(StrToInt(StringGrid1.Cells[i,0])); k:=i; end; m:=1; for i:=k+1 to StringGrid1.ColCount-1 do m:=m*StrToInt(StringGrid1.Cells[i,0]); Label3.Caption:=IntToStr(m); end; procedure TForm1.FormCreate(Sender: TObject); begin Label2.Caption:=''; label3.Caption:=''; end; procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType); begin StringGrid1.ColCount:=StrToInt(Edit2.Text); end; end.
Задача 18. Для десяти выстрелов, координаты которых задаются с клавиатуры, вывести текстовые сообщения о попадании в мишень, определенной заштрихованной областью.
НА ДЕЛФИ
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Button1: TButton; Memo1: TMemo; Label3: TLabel; Edit3: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var x,y,r,i:real; begin x:=strtofloat(edit1.Text); y:=strtofloat(edit2.Text); r:=strtofloat(edit3.Text); //i:=1; //while i<=10 do //begin if (x>=0) and (x<r) and (x>=0) and (y<r) and (y>=0) then Memo1.Lines.Add('стрелок попал') else if (x<=0) and (x>-r) and (y<=0) and (y>-r) then Memo1.Lines.Add('стрелок попал') else if (x<=0) and (x<-r+1) and (y>=0) and (y<r-1) then Memo1.Lines.Add('стрелок попал') else Memo1.Lines.Add('не попал'); //i:=i+1; //end; end; end.
НА С++
#include <vcl.h> #pragma hdrstop #include "Unit1.h" #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){} //--------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) {Form1->Close();} //--------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) {float x,y,r; int i; x=StrToFloat(Edit1->Text); y=StrToFloat(Edit2->Text); r=StrToFloat(Edit3->Text); //i=1; //while (i<=10) //{ if ((x>=0) && (x<r) && (x>=0) && (y<r) && (y>=0)) Memo1->Lines->Add("Стрелок попал"); else if ((x<=0) && (x>-r) && (y<=0) && (y>-r)) Memo1->Lines->Add("Стрелок попал"); else if ((x<=0) && (x<-r+1) && (y>=0) && (y<r-1)) Memo1->Lines->Add("Стрелок попал"); else Memo1->Lines->Add("Не попал"); //i=i+1; //} } Задача 19. Для десяти выстрелов, координаты которых задаются с клавиатуры, вывести текстовые сообщения о попадании в мишень, определенной заштрихованной областью. НА ДЕЛФИ unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); const r=2; var x,y,i:real; begin x:=strtofloat(edit1.Text); y:=strtofloat(edit2.Text); //цикл можно убрать, а можно оставить //10 раз выводит сообщение попал или не попал //i:=1; //while i<=10 do //begin if (sqrt(sqr(x)+sqr(y))<=(sqr(R)+1)) and (y>=0) and (x<=0) then Memo1.Lines.Add('Стрелок попал') else if (x>=0) and (x<=2*R) and (y<=0) and (y>=-R) then Memo1.Lines.Add('Стрелок попал') else Memo1.Lines.Add(`Стрелок не попал`); //i:=i+1; //end; end;end.
НА С++ #include <vcl.h> #include <math.h> #pragma hdrstop #include "Unit1.h" #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){} //--------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) {Form1->Close();} //--------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) {float x,y,i,r; x=StrToFloat(Edit1->Text); y=StrToFloat(Edit2->Text); r=StrToFloat(Edit3->Text); //цикл можно убрать, а можно и оставить //10 раз выводит сообщение попал или не попал //i=1; //while (i<=10) //{ if ((sqrt((x*x)+(y*y))<=((r*r)+1)) && (y>=0) && (x<=0)) Memo1->Lines->Add("Стрелок попал"); else if ((x>=0) && (x<=2*r) && (y<=0) && (y>=-r)) Memo1->Lines->Add("Стрелок попал") ; else Memo1->Lines->Add("Стрелок облажался"); //i=i+1; //} } //--------------------------------------------------------------- Задача 20. Для десяти выстрелов, координаты которых задаются с клавиатуры, вывести текстовые сообщения о попадании в мишень, определенной заштрихованной областью.
НА ДЕЛИФ
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Math, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Label2: TLabel; Label3: TLabel; Edit2: TEdit; Edit3: TEdit; Button1: TButton; Edit1: TEdit; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; i:integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin Edit1.Clear; Edit2.Clear; Edit3.Clear; Memo1.Clear; Edit1.Text:='10'; i:=1; Form1.Caption:='Выстрел 1' end; procedure TForm1.Button1Click(Sender: TObject); var x,y,R:real; k:boolean; begin Edit1.Enabled:=false; x:=StrToFloat(Edit2.Text); y:=StrToFloat(Edit3.Text); R:=StrToFloat(Edit1.Text); k:=(((x<0) and (y<0)) or ((x>0)and (y>sqr(x-1))))and((sqr(x)+sqr(y))<sqr(R)); if k then Memo1.Lines.Add('X= '+FloatToStr(x)+' Y= '+FloatToStr(y)+' : Попал!!!') else Memo1.Lines.Add('X= '+FloatToStr(x)+' Y= '+FloatToStr(y)+' : Промазл!!!'); inc(i); Form1.Caption:='Выстрел '+IntToStr(i); Edit2.Clear; Edit3.Clear; if i>10 then begin Edit2.Enabled:=false; Edit3.Enabled:=false; Button1.Enabled:=false; end; end; end.
НА С++ #include <vcl.h> #include <math.h> #pragma hdrstop #include "Unit1.h" #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int i; __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner){} void __fastcall TForm1::Button2Click(TObject *Sender) {Form1->Close();} void __fastcall TForm1::Button1Click(TObject *Sender) {float x,y,R; bool k; x=StrToFloat(Edit1->Text); y=StrToFloat(Edit2->Text); R=StrToFloat(Edit3->Text); k=(((x<0) && (y<0)) || ((x>0) && (y>((x-1)*(x-1)))))&&(((x*x)+(y*y))<(R*R)); if (k) Memo1->Lines->Add("X= "+FloatToStr(x)+" Y= "+FloatToStr(y)+" : Попал!!!"); else Memo1->Lines->Add("X= "+FloatToStr(x)+" Y= "+FloatToStr(y)+" : Промазал!!!"); i=i+1;Form1->Caption="Выстрел "+IntToStr(i);}
Популярное: Генезис конфликтологии как науки в древней Греции: Для уяснения предыстории конфликтологии существенное значение имеет обращение к античной... Личность ребенка как объект и субъект в образовательной технологии: В настоящее время в России идет становление новой системы образования, ориентированного на вхождение... Как выбрать специалиста по управлению гостиницей: Понятно, что управление гостиницей невозможно без специальных знаний. Соответственно, важна квалификация... Как распознать напряжение: Говоря о мышечном напряжении, мы в первую очередь имеем в виду мускулы, прикрепленные к костям ... ©2015-2024 megaobuchalka.ru Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. (608)
|
Почему 1285321 студент выбрали МегаОбучалку... Система поиска информации Мобильная версия сайта Удобная навигация Нет шокирующей рекламы |