Program BAI_TAP_CHU_DE_LON1; Uses Dos,Crt,graph; Type mang = array [1..10] of string; m1 = array [1..21] of byte; Const dong = 10; old = 15; tg = 60000; MAU=159; mau2=120; Var k:array[1..10] of string; dc:char; Gd,Gm : Integer; Radius,T : Integer; a : m1; f1,f2:m1; n,l,i,h1,h2,p,pm : byte; ss,hv : word; Procedure ConTro(co:byte); Var R : Registers; Begin R.AH:=$01; If co = 0 Then R.CX:=$2000 Else R.CX:=$0B0C; Intr($10,R); End;
Trang 1Program BAI_TAP_CHU_DE_LON1;Uses Dos,Crt,graph;
Type mang = array [1 10] of string; m1 = array [1 21] of byte;
Trang 4end;
ConTro(0);
end;
Procedure writeXYchuoi(x,y:byte;chuoi:string;tt:byte);Begin
Trang 5#80:if chon<max then inc(chon) else chon:=1; #72:if chon>1 then dec(chon) else chon:=max; end;
Until kt=#13;
Taomenu:=chon;
End;
{ -Nhap -}Procedure NHAP;
Var ch,i : byte;
Writexychuoi(28,1,'DAY SO BAN DAU',15);
For i:=1 to n do writexyso(i*4-3,3,old,i);
Trang 6{ -}Procedure clr;
Var x,coti,dongi,cotj,dongj : byte;
Begin
coti:=i*4-3;
cotj:=j*4-3;
writexyso(coti,dong,159,i);
Trang 7if i<j then begin coti:=coti+4;cotj:=cotj-4;end
else begin cotj:=cotj+4;coti:=coti-4;end;
writexyso(coti,dongi,159,i);writexyso(cotj,dongj,159,j);delay(tg); end;
{ -Nho hon -}
Trang 8{ -Chon truc tiep (Selection Sort) -}Procedure SelectionSort(var a:m1;n:byte);
Var i,j,min: byte;
Trang 10Writexychuoi(28,5,'Chen Truc Tiep (Insertion Sort)',14); clr;
For i:=1 to n do writexyso(i*4-3,dong,15,i);
writexyso(k,dong,old,j);delay(tg);
a[j+1]:=a[j];
dec(j);
thoat:=not(nho(x,j));
Trang 13if NhoHon(j,k) then inc(j);
end; {sau buoc nay a[j] la phan tu lien doi lon nhat}
If not nho(x,j) then
Trang 14end;
writexyso(i*4-3,dong,207,n+1);delay(tg); writexyso(i*4-3,dong,old,n+1);delay(tg); end;
Trang 15Writexychuoi(28,5,'Sap xep vun dong (Heap Sort) ',14);
Trang 16while a[i]<x do begin inc(i);inc(ss);
gotoxy(1,18);writeln('So lan so sanh : ',ss);end; while x<a[j] do begin dec(j);inc(ss);
gotoxy(1,18);writeln('So lan so sanh : ',ss);end;
Trang 17if i<r then Sort(i,r);
Trang 18BAR(395,100,GETMAXX-5,GETMAXY-6); setfillstyle(8,3);
Trang 20outtextxy(30,160,'Dung 2 phim mui');
outtextxy(30,180,'ten len - xuong');
outtextxy(30,200,'thuc hien chuc nang,');
outtextxy(30,220,'Enter de quyet dinh');
setcolor(123);settextstyle(2,0,6);outtextxy(400,155,'GVHD:');
Trang 21setcolor(123);settextstyle(2,0,6);outtextxy(400,175,'HUYNH DUONG TRUNG TRUC');
Trang 22l:=0;
case dc of
#80:if i<7 then i:=i+1 else i:=1;
#72:if i>1 then i:=i-1 else i:=7;
Procedure clrr;
Trang 23procedure phanmang(p:byte);
var i,k,l:byte;
begin
k:=1;
Trang 26writexyso(h*4-3,dong,mau,h);delay(tg); end
while (i2<=h2)and(r2<=p)do
begin
inc(h);
a[h]:=f2[i2];
Trang 27xoa(i2*4-3,dong+4);
inc(i2);inc(r2);
writexyso(h*4-3,dong,mau,h);delay(tg); end;
end;
procedure tron2duong;
begin
Trang 29writeXYchuoi(5,18,'So lan so sanh : ',old);writeln(ss);
writeXYchuoi(5,19,'So lan phan mang :',old);writeln(' ',pm);
writeXYchuoi(8,21,' Day tren da duoc sap xep theo phuong phap sap xep Merger Sort co thu tu',205);
readln;
end;
Trang 30fillellipse(120,360,65,65); setfillstyle(1,16);
fillellipse(105,335,57,57); setfillstyle(1,11);
fillellipse(105,389,54,54); setfillstyle(1,14);
fillellipse(105,360,51,51); settextstyle(4,0,1);
Trang 32outtextxy(50,22,'TRUONG CAO DANG SU PHAM SOC TRANG');
setcolor(123); outtextxy(175,332,'THACH THI PHA NI');
setcolor(14);
settextstyle(0,0,2);
outtextxy(122,112,'NIEN KHOA: 2009-2010');
Trang 34if huong<30 then huong:=huong+30;
for i:=0 to sodiem-1 do
Begin
tgy:=tyley*sin(2*Pi*i/sodiem);
tgx:=2*Pi*i*tyleX/sodiem;
x[i+1]:=gocx+round(tgx*cos(huong)*tgy*sin(huong)); x[i+1]:=gocx-round(tgx*sin(huong)*tgy*cos(huong)); End;
Trang 35End;
Procedure Ve;
var
Trang 36initgraph (gd,gm,'D:/turbo pascal/BGI');
if graphresult<>grOK then Exit;
Trang 37ve;
end;
Until Keypressed; closegraph;
End;
Begin
gm:=Detect;
InitGraph(gm,gd,''); gt;
Readln;
manhinhchinh; ve_bong;
CloseGraph;
end