Визуальное программирование. Министерство образования и науки РФ
Министерство образования и науки РФ
Федеральное государственное автономное образовательное
Учреждение высшего профессионального образования
«Казанский (Приволжский) федеральный университет»
ИНСТИТУТ ВЫЧИСЛИТЕЛЬНОЙ МАТЕМАТИКИ И ИНФОРМАЦИОННЫХ ТЕХНОЛОГИЙ
Кафедра информатики и вычислительных технологий
Специальность: "Прикладная информатика в образовании"
Практикум ЭВМ
Выполнила: студентка группы 901 пио
Газиева А.Ф.
Руководитель: Галиуллин Д.К.
Казань – 2012
Вариант 1.
Код программы(для рис.1):
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var x,y:real;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('x=');
readln(x);
write('y=');
readln(y);
if ((sqr(x)+sqr(y)<=25) and (x>=0))or((sqr(x)+sqr(y)<=9) and(x<=0) and (y>=0))
or((y>=-5/3*x-5) and(x<=0) and(y<=0))
then writeln('yes')
else writeln('no');
readln;
end.
Код программы:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var n,a,b,s:integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('vvedite 2x znachnoe chislo:');
readln(n);
a:=n mod 10;
b:=n div 10;
s:=a+b;
if s mod 2=0 then writeln('verno')
else writeln('ne verno');
readln
end.
program Project3;
{$APPTYPE CONSOLE}
Uses SysUtils;
var p,eps,a:real;
k:integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('eps=');
readln(eps);
p:=1; k:=2; a:=1-1/sqr(k);
while abs(1/sqr(k))>=eps do begin
p:=p*a;
k:=k+1;
a:=(1-1/sqr(k)); end;
writeln('P=',p:8:6);
readln; readln;
end.
program Project4;
{$APPTYPE CONSOLE}
Uses SysUtils;
var x0,x1,a:real;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('a='); readln(a);
if a<=1 then begin if 2*a<0.95 then x0:=2*a else x0:=0.95 end
else if a<25 then x0:=a/5
else x0:=a/25;
x1:=4/5*x0+a/(5*sqr(sqr(x0)));
while 5/4*a*abs(x1-x0)>=0.000001 do
begin
x0:=x1;
x1:=4/5*x0+ a/(5*sqr(sqr(x0)));
end;
writeln('xn=',x1:8:6);
readln;
end.
program Project5;
{$APPTYPE CONSOLE}
uses SysUtils;
var N,M,P:longint; i,k:integer;
begin
write('Vvedite naturalnoe chislo N='); readln(N);
M:=N; P:=0;
while M>0 do
begin i:=M mod 10; P:=P*10+i; M:=M div 10; end;
if P=N then write('Palindrom')
else write('Ne palindrom');
readln
end.
program Project6;
{$APPTYPE CONSOLE}
uses SysUtils;
var a,b:array[1..20] of integer;
i,j:integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
for i:=1 to 20 do
read(a[i]);
j:=1;
for i:=20 downto 11 do begin
b[j]:=a[i]; b[j+1]:=a[i-10]; j:=j+2
end;
for j:=1 to 20 do
write(b[j],' ');
readln;
readln
end.
program Project7;
{$APPTYPE CONSOLE}
uses SysUtils;
var a:array[1..30] of integer; i,n:integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('n=');
readln(n);
Writeln('vvedite massiv:');
for i:=1 to 2*n do
read(a[i]);
for i:=1 to n do
begin
write(a[i], ' ');
write(a[n+i],' ');
end;
readln;
readln; end.
program Project8; {$APPTYPE CONSOLE}
uses SysUtils;
var a:array[1..10,1..10] of real; x:real; i,j:integer;
begin
write('x='); readln(x);
i:=1;
for j:=1 to 10 do
a[i,j]:=exp(ln(x)*(j-1));
i:=10;
for j:=10 downto 1 do
a[i,11-j]:=exp(ln(x)*(j-1));
j:=1;
for i:=1 to 10 do
a[i,j]:=exp(ln(x)*(i-1));
j:=10;
for i:=10 downto 1 do
a[11-i,j]:=exp(ln(x)*(i-1));
for i:=1 to 10 do begin
for j:=1 to 10 do
write(a[i,j]:6:1);
writeln; end;
readln; end.
program Project9;
{$APPTYPE CONSOLE}
uses SysUtils;
var a:array[1..10,1..10] of integer;
i,j,n,m,k,p:integer;
begin { TODO -oUser -cConsole Main : Insert code here }
write('vvedite kol-vo strok n='); readln(n);
write('vvedite kol-vo stolbsov m='); readln(m);
for i:=1 to n do
for j:=1 to m do read(a[i,j]);
k:=0; p:=1;
for j:=1 to m do
if a[5,j] mod 2=1 then
begin
k:=k+1;
p:=p*a[5,j]
end;
write('k=',k, ' p=', p);
readln;
readln
end.
program Project10;
{$APPTYPE CONSOLE}
Uses SysUtils;
var s1,s2:string; i:integer;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('vvedite stroku:');
readln(s1);
s2:='';
i:=pos('e',s1);
s2:=copy(s1,1,i);
delete(s1,1,i);
i:=pos('e',s1);
s2:=s2+copy(s1,i,length(s1));
writeln(s2);
readln
end.
program P11dpr;
{$APPTYPE CONSOLE}
uses SysUtils;
var s,s1,S2:string;
i,j,k,t,p:integer;
w:boolean;
begin
writeln('Vvedite text razdelenniy probelami:');
readln(s);
s:=s+' ';
p:=1;
i:=1;
while i<=length(s) do begin
w:=false;
while not(w) do begin
if (s[i]<>' ') and(s[i-1]=' ') then
begin w:=true; t:=p; p:=i; end; i:=i+1; end;
s1:=copy(s,t,p-t); s1[3]:='a'; delete(s,t,p-t); insert(s1,s,t);
end;
write(s);
readln;
end.
program Project122;
{$APPTYPE CONSOLE}
uses SysUtils;
type mas=array[1..30] of integer;
var x,y:mas; n,m,min,a,b:integer;
procedure vvod(k:integer; var z:mas);
var i:integer;
begin for i:=1 to k do read(z[i]);
end;
procedure minn(z:mas; a:integer; var min:integer);
var i:integer;
begin min:=z[1];
for i:=2 to n do
if z[i]<min then min:=z[i];
if min=z[a] then writeln('verno') else writeln('ne verno') end;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('vvedite kol-vo elementov 1-go massiva n='); readln(n);
write('vvedite kol-vo elementov 2-go massiva m=');readln(m);
vvod(n,x);
vvod(m,y);
write('vvedite nomer dlya proverki min elementa 1-go massiva='); readln(a);
write('vvedite nomer dlya proverki min elementa 2-go massiva=');readln(b);
minn(x,a,min);
minn(y,b,min);
readln; readln;
end.
program Project13;
{$APPTYPE CONSOLE}
uses SysUtils;
var ss:string;
function kol(s: string; k: char): integer;
var i, n: integer;
begin
n := 0;
for i := 1 to length(s) do
if s[i] = k then n:=n+1;
kol := n
end;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('vvedite stroku simvolov:');
readln(ss);
writeln('kol-vo simvolov "r"=',kol(ss,'r'));
writeln('kol-vo simvolov "k"=',kol(ss,'k'));
writeln('kol-vo simvolov "t"=',kol(ss,'t')); readln; end.
ТЕКСТОВЫЕ ФАЙЛЫ
1. Дан массив целых чисел а1,…, аn (n<=10). Сформировать текстовый файл по следующему правилу: первая строка файла состоит из букв «А», количество которых а1 , вторая строка из букв «Б», количество которых а2 и т.д.
program Project14;
{$APPTYPE CONSOLE}
uses SysUtils;
var a:array[1..10] of integer;
f:textfile;
i,n,l:integer;
s:string;
begin
{ TODO -oUser -cConsole Main : Insert code here }
write('vvedite kol-vo elementov massiva, n= '); readln(n);
for i:=1 to n do read(a[i]);
assignfile(f,'C:\Users\Алина\Desktop\прак ЭВМ\pr14.txt');
rewrite(f);
s:='ABCDEFGHIJ';
for i:=1 to n do begin
for l:=1 to a[i] do
write(f,s[i],' ');
writeln(f)
end;
closefile(f);
end.
Визуальное программирование
Одномерные массивы.
1.Дан массив X1,…,Xn. Поменять местами первый и последний элемент, второй и предпоследний, и т д.
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
Tform1 = class(Tform)
Memo1: Tmemo;
Edit1: Tedit;
Memo2: Tmemo;
Memo3: Tmemo;
Button1: Tbutton;
Label1: Tlabel;
Label2: Tlabel;
Label3: Tlabel;
Button2: Tbutton;
Button3: Tbutton;
Button4: Tbutton;
procedure Button1Click(Sender: Tobject);
procedure Button2Click(Sender: Tobject);
procedure Button3Click(Sender: Tobject);
procedure Button4Click(Sender: Tobject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: Tform1;
x:array [1..30] of integer;
var n,I,p,k:integer;
implementation
{$R *.dfm}
procedure Tform1.Button1Click(Sender: Tobject);
begin
n:=strtoint(edit1.Text);
for i:=1 to n do begin
x[i]:=random(201)-100;
memo2.lines.Add(inttostr(x[i]))
end;
{x[i]:=strtoint(memo1.Lines[i-1]); }
end;
procedure Tform1.Button2Click(Sender: Tobject);
begin
p := n div 2;
for i:= 1 to p do
begin
k := x[i];
x[i]:=x[n+1-i];
x[n+1-i]:=k;
end;
for i:=1 to n do memo3.lines.Add(inttostr(x[i]))
end;
procedure Tform1.Button3Click(Sender: Tobject);
begin
form1.close
end;
procedure Tform1.Button4Click(Sender: Tobject);
begin
memo2.Clear;
memo3.Clear;
edit1.Text:=’’
end;
end.
Двумерные массивы.
1. Дан двумерный массив порядка m*m. В каждой строке этого массива заменить диагональный элемент на максимальный элемент этой строки.
unit viz2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
Memo1: TMemo;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Label3: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var m,i,j,maxi:integer;
a:array [1..30,1..30] of real;
p:real;
begin
m:=strtoint(edit1.Text);
StringGrid1.RowCount:=m;
StringGrid1.ColCount:=m;
StringGrid2.RowCount:=m;
StringGrid2.ColCount:=m;
for i:=1 to m do
for j:=1 to m do
begin
a[i,j]:=random(201)-100;
Stringgrid1.Cells[j-1,i-1]:=floattostr(a[i,j]);
end;
{a[i,j]:=strtofloat(StringGrid1.Cells[j-1, i-1]); }
for i:=1 to m do begin
maxi:=1;
for j:=1 to m do
if a[i,j]>a[i,maxi] then maxi:=j;
for j:=1 to m do
if i=j then a[i,j]:=a[i,maxi]
end;
for i:=1 to m do
for j:=1 to m do
Stringgrid2.Cells[j-1,i-1]:=floattostr(a[i,j]);
end;
end.
Рисунок
Нарисовать произвольный рисунок.
unit Unit1_ris;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private { Private declarations }
public { Public declarations }
end;
var Form1: TForm1;
implementation {$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
form1.Canvas.MoveTo(100,150);
form1.Canvas.lineto(100,350);
form1.Canvas.lineto(400,350);
form1.Canvas.lineto(400,150);
form1.Canvas.lineto(100,150);
form1.Canvas.lineto(250,50);
form1.Canvas.lineto(400,150);
form1.Canvas.MoveTo(220,200);
form1.Canvas.lineto(220,280);
form1.Canvas.lineto(280,280);
form1.Canvas.lineto(280,200);
form1.Canvas.lineto(220,200);
form1.Canvas.MoveTo(220,225);
form1.Canvas.lineto(280,225);
form1.Canvas.MoveTo(250,225);
form1.Canvas.lineto(250,280);
form1.Canvas.MoveTo(400,350);
form1.Canvas.lineto(500,300);
form1.Canvas.lineto(500,100);
form1.Canvas.lineto(400,150);
form1.Canvas.MoveTo(500,100);
form1.Canvas.lineto(350,0);
form1.Canvas.lineto(250,50);
form1.Canvas.ellipse(230,90,280,130);
form1.Canvas.ellipse(10,10,80,80);
form1.Canvas.MoveTo(70,70);
form1.Canvas.lineto(80,120);
form1.Canvas.lineto(110,90);
form1.Canvas.lineto(70,70);
form1.Canvas.MoveTo(80,45);
form1.Canvas.lineto(130,65);
form1.Canvas.lineto(130,25);
form1.Canvas.lineto(80,45);
form1.Canvas.MoveTo(45,80);
form1.Canvas.lineto(25,140);
form1.Canvas.lineto(60,140);
form1.Canvas.lineto(45,80);
form1.Canvas.brush.color:=clyellow;
form1.Canvas.floodfill(250,300,clblack,fsborder);
form1.Canvas.floodfill(450,300,clblack,fsborder);
form1.Canvas.floodfill(30,30,clblack,fsborder);
form1.Canvas.floodfill(75,80,clblack,fsborder);
form1.Canvas.floodfill(85,45,clblack,fsborder);
form1.Canvas.floodfill(45,85,clblack,fsborder);
form1.Canvas.brush.color:=clblue;
form1.Canvas.floodfill(100,10,clblack,fsborder);
form1.Canvas.brush.color:=claqua;
form1.Canvas.floodfill(250,60,clblack,fsborder);
form1.Canvas.brush.color:=cllime;
form1.Canvas.brush.style:=bscross;
form1.Canvas.floodfill(430,100,clblack,fsborder);
end;
end.
Тест
1. Создать тест-программу на произвольную тему.
unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;Label1: TLabel; Button2: TButton; Label2: TLabel; Label3: TLabel; Label4: TLabel; Edit1: TEdit;Edit2: TEdit; Edit3: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private { Private declarations }
public{ Public declarations } end;
var Form1: TForm1;fam,n,kurs:string;
implementation
uses Unit2,Unit3; {$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
fam:=edit1.Text;
n:=edit2.Text;
kurs:=edit3.Text;
form2.show
end;
procedure TForm1.Button2Click(Sender: TObject);
begin form1.close end;
end.
unit Unit2;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls;
type
TForm2 = class(TForm)
Button1: TButton; Label1: TLabel;RadioButton1: TRadioButton;RadioButton2: TRadioButton;
RadioButton3: TRadioButton;RadioButton4: TRadioButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private{ Private declarations }
public { Public declarations }end;
var Form2: TForm2; v,o1,o2,o3,o4,o:array[1..30] of string; ball,j,i,ot:integer; f,t:textfile; p:real;
implementation uses Unit1, Unit3; {$R *.dfm}
procedure TForm2.FormShow(Sender: TObject);
begin assignfile(f,'D:\lina\эвм\тест\my\europe.txt');reset(f);
for i:=1 to 5 do begin
readln(f,v[i]); readln(f,o1[i]); readln(f,o2[i]); readln(f,o3[i]); readln(f,o4[i]); readln(f,o[i]); end;
label1.caption:=v[1];
RadioButton1.caption:=o1[1]; radiobutton2.caption:=o2[1];
radiobutton3.caption:=o3[1]; radiobutton4.caption:=o4[1]; ball:=0; i:=1
end;
procedure TForm2.Button1Click(Sender: TObject);
begin if i<=5 then begin
if (radiobutton1.Checked) and (radiobutton1.caption=o[i]) then ball:=ball+1 else
if (radiobutton2.Checked) and (radiobutton2.caption=o[i]) then ball:=ball+1 else
if (radiobutton3.Checked) and (radiobutton3.caption=o[i]) then ball:=ball+1 else
if (radiobutton4.Checked) and (radiobutton4.caption=o[i]) then ball:=ball+1;
radiobutton1.Checked:=false; radiobutton2.Checked:=false; radiobutton3.Checked:=false;
radiobutton4.Checked:=false; end;
if i<=4 then begin
label1.caption:=v[i+1]; RadioButton1.caption:=o1[i+1]; radiobutton2.caption:=o2[i+1];
radiobutton3.caption:=o3[i+1]; radiobutton4.caption:=o4[i+1]; i:=i+1; end
else begin p:=ball*100/5;
if p<45 then ot:=2;
if (p>=45) and (p<65) then ot:=3;
if (p>=65) and (p<85) then ot:=4;
if p>=85 then ot:=5; form3.show end;
end;
end.
unit Unit3;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TForm3 = class(TForm)
Label1: TLabel; Edit1: TEdit;Label2: TLabel;Edit2: TEdit;Button1: TButton; Label3: TLabel;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
private{ Private declarations }
public{ Public declarations }
end;
var Form3: TForm3;
implementation
uses Unit1,Unit2; {$R *.dfm}
procedure TForm3.FormShow(Sender: TObject);
begin
edit1.Text:=inttostr(ball); edit2.Text:=inttostr(ot); label3.Caption:=fam+' '+n+', '+kurs;
assignfile(t,'D:\lina\эвм\тест\my\rezultat.txt');append(t); writeln(t,fam); writeln(t,n);
writeln(t,'gruppa: ',kurs); writeln(t,'kol-vo pravilnix otvetov: ',ball);
writeln(t,'otsenka: ',ot); closefile(t)
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
form3.close; form2.close; form1.close;
end; end.
Поиск по сайту: