Slide Cau Truc Du Lieu Va Giai Thuat 2 - Nguyen Trung Hoa - Smith.N Studio
Do an Cau Truc Du Lieu
description
Transcript of Do an Cau Truc Du Lieu
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
Lời Nói Đầu
Khi giải quyết một bài toán trên máy tính điện tử thì ta thường đề cập đến cấu trúc dữ liệu và giải thuật, vì cấu trúc dữ liệu và giải thuật là nền tảng , là cơ sở cho mọi bài toán . Giải thuật là tập hợp những câu lệnh chặt chẽ nhằm thao tác với một đối tượng nào đó sao cho kết quả là tốt nhất , tốn ít dung lượng hệ thống và thời gian để thực thi chương trình là ngắn nhấtDữ liệu là đối tượng để sử lý trên máy tính điện tử . Một bài toán đặt ra có thể có nhiều cách giải quyết khác nhau Mô hình quản lý danh sách sinh viên có sử dụng giao diện đồ họa sử dụng biến động và danh sách liên kết để tổ chức quản lý bộ nhớ, cấp phát bộ nhớ và giải phóng bộ nhớ được thực thi một cách trình tự , tiết kiệm không gian nhớ .
Trước khi trình bày đề tài này chúng em xin chân thành cảm ơn thầy cô trong khoa Công Nghệ Thông Tin và đặc biệt là thầy Phan Chí Tùng đã truyền đạt những kiến thức để chúng em hoàn thành đề tài này.Vì thời gian thực hiện chương trình và kiến thức có hạn nên không tránh những sai sót, chúng em mong nhận được sự góp ý của quý thầy cô để chương trình hoàn thiện hơn.
Đà Nẵng, Ngày 10/11/2007 Sinh Viên Thực Hiện : Võ Văn Trí Nguyễn Thanh Trung Lớp : 05T1
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 1
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
ĐỒ ÁN MÔN HỌCCấu Trúc Dữ Liệu
Đề Tài: MÔ HÌNH QUẢN LÍ DANH SÁCH SINH VIÊN Giáo Viên Hướng Dẫn : Phan Chí Tùng Sinh Viên Thực Hiện : Võ Văn Trí Nguyễn Thanh Trung Lớp : 05T1
¶.Giới thiệu về môn cấu trúc dữ liệu: Ngày nay nhiều ngôn ngữ lập trình ra đời ,với những thuận lợi riêng của từng ngôn ngữ,dù từ bậc cao đến bậc thấp vẫn đều có một đặc điểm chung đó là được xây dựng trên giải thuật và cấu trúc dữ liệu. Cấu trúc dữ liệu và giải thuật luôn được xếp hàng đầu trong mười khối khối kiến thức cơ bản của khoa học máy tính
Trong lập trình có cấu trúc người lập trình phải chú ý về mặt cấu trúc của các vấn đề sau:
- Cấu trúc về mặt dữ liệu: từ các dữ liệu đã có xây dựng các dữ liệu phức tạp hơn.
- Cấu trúc về mặt lệnh: Từ các lệnh đã có ta có thể nhóm chúng lại với nhau và đặt giữa các từ khoá thành các câu lệnh phức tạp hay lệnh ghép.
- Cấu trúc về mặt chương trình: Một chương trình có thể chia thành các chương trình con độc lập (gọi là môđun) , xây dựng các thư viện chương trình để sử dụng lâu dài…..
¶.Cấu trúc dữ liệu và vấn đề liên quan:
Với giải thuật:
Giải thuật cung cấp cho người lập trình các bước để thực hiện một yêu cầu cụ thể , thông thường có nhiều cách cài đặt kiểu dữ liệu khác nhau , chúng ta phải xem xét, đánh giá giải thuật để lựa chọn phương pháp tối ưu nhất , tốn ít tài nguyên hệ thống, thời gian thực thi chương trình là ít nhất
Với ngôn ngữ lập trình:
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 2
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
Các ngôn ngữ lập trình cung cấp các dữ liệu cơ sở cho người lập trình , ngoài ra người lập trình còn có thể định nghĩa các kiểu dữ liệu mới để thuận tiện cho việc lập trình
¶.Thuật toán: Vì đây là đồ án môn cấu trúc dữ liệu và thuật toán nên trong bài báo cáo này chúng em chỉ nêu lên thuật toán quản lí danh sách sinh viên còn giao diện đồ hoạ sẽ không trình bày trong bài báo cáo này mà chỉ đưa ra các thư viện mà chúng em đã tạo để phục vụ cho đề tài này. I.1.Get list : Tạo danh sách sinh viên. + Nhập các thông số của sinh viên vào vùng nhớ được chỉ bởi biến con trỏ p.
+Tìm vị trí thoã mãn để đưa sinh viên được chỉ bởi biến con trỏ p vào. - Tìm vị trí sao cho after chỉ vào phần tử đứng ngay sau p,before chỉ tới
phần tử đứng ngay trước phần tử chỉ bởi biến con trỏ p.- Cho trường liên kết của p chỉ tới phần tử chỉ bởi after- Nếu after chi tới phần tử đầu tiên thì ta cho F chỉ tới p,nếu không thì
ta cho trường liên kết before chỉ tới p. + Lặp lại quá trình trên cho đên khi nhập hết những sinh viên cần nhập.
I.2. Thủ tục Getlist : after=F; while((after!=NULL)&&(strcmp((*after).ht,y)<0))
{ before=after; after=(*after).next; } (*p).next=after; if(F= =after)F=p; else (*before).next=p;
II.1. Add list :Thêm một sinh viên vào danh sách.
+ Thuật toán giống như getlist + Nhưng khác là ở đây chỉ được nhập thêm một sinh viên vào danh sách.
III.1. Find : Tìm một sinh viên có trong danh sách không + Cho biến con trỏ p chỉ đến phần tử đầu tiên.
+ Duyệt qua từng sinh viên cho đến khi tìm thấy sinh viên cần tìm hoặc tìm đến cuối danh sách mà không có. III.2. Thủ tục Find : p=F; while((p!=NULL)&&(strcmp((*p).ht,y))!=0)
p=(*p).next; if((p!=NULL)&&(strcmp((*p).ht,y)==0))return(p);
else return(null); IV.1. Delete :Xoá một sinh viên ra khỏi danh sách.
+ Cho biến con trỏ p duyệt từ đầu cho đên cuối danh sách,và before chỉ tới phần tử đứng ngay trước phần tử chỉ bởi biến con trỏ p.
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 3
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
+ Nếu tìm có phần thì :- Nếu phần tử cần xoá là phần tử đầu tiên thì ta cho F chỉ tới phần tử
giôngd như p chỉ.- Nếu không thì ta cho before chỉ tới phần tử giống như phần tử p chỉ\- Xoá phần tử chỉ bởi biến p.
IV.2. Thủ tục Delete : p=F;
while((p!=NULL)&&(p!=t)) { before=p;
p=(*p).next; }
if(p!=NULL) { if(F==t)F=(*F).next; else (*before).next=(*t).next; }
delete(t); V.1. Fix : Thủ tục chỉnh sửa nội dung cuả một sinh viên. + Cho biến p duyệt từ đầu cho đến cuối danh sách để tìm vị trí của sinh viên cần chỉnh sửa.
+ Ta nhập các thông tin mới cần sửa đổi cho sinh viien này. + Ta gán các thông số này vào bản ghi do biến p đang chỉ.
V.2. Thủ tục Fix : p=F; while((p!=NULL)&&(strcmp((*p).ht,y))!=0)
p=(*p).next; printf("+ Gioi tinh sv : ");gets(g);
printf("+ Nhap ma sv : ");cin>>x; printf("+ Nam sinh sv : ");cin>>z; printf("+ Nhap diem toan: ");cin>>d1;
printf("+ Nhap diem li : ");cin>>d2; printf("+ Nhap diem hoa : ");cin>>d3;
tb=(d1*2+d2+d3)/4; if(tb<5)strcpy((*p).xl,"yeu"); else if((tb>=5)&&(tb<6.5))strcpy((*p).xl,"tb"); else if((tb>=6.5)&&(tb<8))strcpy((*p).xl,"kha"); else if(tb>=8)strcpy((*p).xl,"gioi");
(*p).ma=x; strcpy((*p).ht,y);
(*p).ns=z; strcpy((*p).gt,g); (*p).diem1=d1; (*p).diem2=d2; (*p).diem3=d3; (*p).dtb=tb;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 4
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
¶.Chương trình chính:
#include<conio.h>#include<stdio.h>#include<dos.h>#include<mouse.h>#include<vantri9.h>#include<stdlib.h>#include<graphics.h>#include<gt1.h>#include<string.h>int toa_do_trai(int x_text, int y_text){
int result;result=0;
if ((x_text+1 >=605) && (x_text+1 <=625)&&( y_text+1 >=15) && (y_text+1 <=25))
result =1;return(result);
}void tac_dong_chuot_trai(int MouseX,int MouseY,int MouseClick){ char t_do_moi ; t_do_moi = toa_do_trai(MouseX, MouseY); if ( t_do_moi!= 0)
if(MouseClick==1)exit(1);}void main (void){ clrscr(); int mh=0,mode,h,j,m,a[2][3]; initgraph(&mh,&mode,"c:\\TC\\BGI"); setbkcolor(1); nen(); lich2(); int t,r,i,x,y,muose_x,muose_y;
setviewport(10,35,500,445,1); khoi_tao(); hien(); do { t=vi_tri(&muose_x,&muose_y);
thoigian();x=muose_x;y=muose_y;toado(x,y); switch(t) { case 1:tac_dong_chuot_trai(x, y,t);
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 5
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
if((muose_x>=10)&&(muose_x<=62)&&(muose_y>=447) &&(muose_y<=468)){ doi_mau();delay(100);
setcolor(14); an();
start(); hien();
do{ t=vi_tri(&muose_x,&muose_y); toado(muose_x,muose_y); thoigian(); }
while(t!=1); an();clearviewport();hien();
if((muose_x>=12)&&(muose_x<=140)&&(muose_y>=365) &&(muose_y<=385)&&(t==1)){an();gt();hien();}
if((muose_x>=12)&&(muose_x<=140)&&(muose_y>=390) &&(muose_y<=410)&&(t==1)){an();tri();hien();}
if((muose_x>=70)&&(muose_x<=140)&&(muose_y>=410) &&(muose_y<=445)&&(t==1)){ an();exit1();hien(); do{ do{ t=vi_tri(&muose_x,&muose_y);
toado(muose_x,muose_y); thoigian(); }while(t!=1);
if((muose_x>=240)&&(muose_x<=300)&&(muose_y>=185) &&(muose_y<=215)&&(t==1))exit2();if((muose_x>=325)&&(muose_x<=390)&&(muose_y>=185) &&(muose_y<=215)&&(t==1)){ an();clearviewport();hien();break;}
}while(1);
}
}break; case 2:
an(); me_nu1(x,y); hien();
do { t=vi_tri(&muose_x,&muose_y); toado(muose_x,muose_y);
thoigian(); }
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 6
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
while(t!=1); an(); clearviewport(); hien(); switch(t) { case 1:t=vi_tri(&muose_x,&muose_y);
if((muose_x>=x+1)&&(muose_x<=x+90)&&(muose_y>=y+1) &&(muose_y<=y+20))
{ getlist(F); do{
do{ t=vi_tri(&muose_x,&muose_y); toado(muose_x,muose_y); thoigian(); }while(t!=1);
if((muose_x>=120)&&(muose_x<=300)&&(muose_y>=360) &&(muose_y<=380)){an();clearviewport();Add1(F);hien();}if((muose_x>=320)&&(muose_x<=480)&&(muose_y>=360) &&(muose_y<=380)){an();clearviewport();hien();break;}
} while(1);
}if((muose_x>=x+1)&&(muose_x<=x+90)&&(muose_y>=y+20) &&(muose_y<=y+40)){an();nen();lich2();hien();break;}if((muose_x>=x+1)&&(muose_x<=x+90)&&(muose_y>=y+40) &&(muose_y<=y+60)){ an();Add(F);hien();break;}if((muose_x>=x+1)&&(muose_x<=x+90)&&(muose_y>=y+60) &&(muose_y<=y+80)){an();Delete(F);hien();break;}if((muose_x>=x+1)&&(muose_x<=x+90)&&(muose_y>=y+80) &&(muose_y<=y+100)){an();Fix(F);hien();break;}if((muose_x>=x+1)&&(muose_x<=x+90)&&(muose_y>=y+100) &&(muose_y<=y+120)){an();Find(F);hien();break;}if((muose_x>=x+1)&&(muose_x<=x+90)&&(muose_y>=y+120) &&(muose_y<=y+140)){ an();exit1();hien();
do{ do{ t=vi_tri(&muose_x,&muose_y);
toado(muose_x,muose_y); thoigian(); } while(t!=1);
if((muose_x>=240)&&(muose_x<=300)&&(muose_y>=185)&&(muose_y<=215))exit2();
if((muose_x>=325)&&(muose_x<=390)&&(muose_y>=185) &&(muose_y<=215)){ an();clearviewport();hien();break;}
}
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 7
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
while(1); }
} break;
} } while(1); getch(); }
¶.Chương viện đồ họa sử dụng trong chương trình: Thư viện vantri9.h
#include<conio.h>#include<stdio.h>#include<graphics.h>#include<dos.h>#include<stdlib.h>#include<string.h>#include<conio.h>#include<string.h>#include<stdio.h>#include<iostream.h> typedef char infor1[20]; typedef float infor2; typedef int infor3; struct element { infor3 ma;
infor1 ht;infor3 ns;infor1 gt;infor2 diem1;infor2 diem2;infor2 diem3;infor2 dtb;infor1 xl;element *next;
}; typedef element *List;
List F,p;infor3 x,z;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 8
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
infor1 y,g;infor2 d1,d2,d3,tb;
void nen(){ int mh=0,mode; initgraph(&mh,&mode,"c:\\TC\\BGI"); setbkcolor(1); setlinestyle(0,0,3); //tren1 setcolor(4); line(5,5,630,5); line(5,10,630,10); setcolor(15); line(5,8,630,8); outtextxy(160,15,"MO HINH QUAN LI DANH SACH SINH VIEN");
//tren2 setcolor(4); line(5,27,630,27); line(5,32,630,32); setcolor(15); line(5,30,630,30); //duoi setcolor(4); line(5,473,630,473); line(5,468,630,468); setcolor(15); line(5,471,630,471);
//trai setcolor(4); line(4,4,4,473); line(10,10,10,469); setcolor(15); line(7,7,7,469); //phai setcolor(4); line(630,4,630,474); line(624,11,624,469); setcolor(15); line(627,8,627,469); //doc setcolor(4);
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 9
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
line(597,10,597,25); line(603,10,603,25); setcolor(15); line(600,10,600,28); setcolor(14); settextstyle(4,0,1); outtextxy(607,5,"X"); setcolor(15); line(8,30,627,30); //start ngang setlinestyle(0,0,1); setcolor(4); line(10,447,62,447); //start doc line(62,447,62,468); setcolor(4); setfillstyle(1,12); floodfill(15,449,4); setcolor(14); outtextxy(15,445,"Start");}void doi_mau() { setcolor(14); rectangle(10,447,62,468); delay(100); setcolor(4); rectangle(10,447,62,468); }void me_nu(int x,int y){ setcolor(15); setviewport(12,35,530,445,1); setlinestyle(0,0,0); rectangle(x+30,y,x+120,y+140); setfillstyle(1,7); floodfill(x+40,y+10,15); setcolor(10); rectangle(x+15,y,x+30,y+140); setfillstyle(1,10); floodfill(x+16,y+2,10); setcolor(4); settextstyle(0,1,1); outtextxy(x+27,y+2,"vo van tri 05t1"); setcolor(9);
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 10
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
settextstyle(2,0,6); outtextxy(x+40,y+2,"Getlist"); outtextxy(x+38,y+19,"refresh"); outtextxy(x+38,y+39," Add"); outtextxy(x+38,y+59," Delete"); outtextxy(x+40,y+79," Fix"); outtextxy(x+53,y+99,"Find"); outtextxy(x+60,y+119,"Exit");
setcolor(8); line(x+30,y+20,x+120,y+20); line(x+30,y+40,x+120,y+40); line(x+30,y+60,x+120,y+60); line(x+30,y+80,x+120,y+80); line(x+30,y+100,x+120,y+100); line(x+120,y,x+120,y+140); line(x+30,y+120,x+120,y+120); line(x+15,y+140,x+120,y+140); line(x+30,y,x+30,y+139); setcolor(15); line(x+15,y,x+15,y+139); line(x+15,y,x+30,y); }//gioi han me nuvoid me_nu1(int x,int y) { x=x-20;y=y-35; if((x>=10)&&(x<=520)&&(y>=30)&&(y<=380))me_nu(x,y); else if((x<=10)&&(y>=15)&&(y<=380))me_nu(x,y); else if((x>=10)&&(x<=520)&&(y<=50))me_nu(x,y); else if((x>=520)&&(y>=15)&&(y<=380))me_nu(x,y); else if((x>=15)&&(x<=520)&&(y>=380))me_nu(x,y); } //me nu start void start() { setviewport(12,35,530,445,1); setlinestyle(0,0,1); rectangle(3,300,140,446); setfillstyle(1,2); floodfill(10,310,14); line(3,320,140,320); line(3,350,140,350); line(3,380,140,380); line(3,410,140,410);
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 11
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
setfillstyle(1,5); floodfill(10,310,14); settextstyle(0,0,1); outtextxy(10,310," Administrators"); outtextxy(35,335,"Gioi thieu"); outtextxy(35,360,"VO VAN TRI"); line(70,380,70,446); outtextxy(10,390,"Restart"); outtextxy(73,390,"Turn off"); }void lich2() { int ngay,i,thu,thang,nam; union REGS v,r;
v.h.ah=0x2a; intdos(&v,&r);
thu=r.h.al; ngay=r.h.dl; thang=r.h.dh; nam=r.x.cx; setcolor(2); rectangle(538,60,620,300); setfillstyle(1,2); floodfill(545,100,2); setcolor(15); line(583,64,583,80); line(584,80,616,80); setcolor(7); line(538,60,538,300); line(538,300,620,300); setcolor(4); settextstyle(0,0,1); gotoxy(74,5);printf("%d",nam);
for(i=1;i<=12;i++) switch(i) { case 1:if(thang==1)outtextxy(545,69,"JAN-");
case 2:if(thang==2)outtextxy(545,69,"FEB-"); case 3:if(thang==3)outtextxy(545,69,"MAR-"); case 4:if(thang==4)outtextxy(545,69,"APR-"); case 5:if(thang==5)outtextxy(550,69,"MAY-"); case 6:if(thang==6)outtextxy(545,69,"JUN-"); case 7:if(thang==7)outtextxy(545,69,"JUL-"); case 8:if(thang==8)outtextxy(545,69,"AUG-");
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 12
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
case 9:if(thang==9)outtextxy(545,69,"SEP-"); case 10:if(thang==10)outtextxy(545,69,"OCT-"); case 11:if(thang==11)outtextxy(545,69,"NOV"); case 12:if(thang==12)outtextxy(545,69,"DEC-");}
setcolor(14); settextstyle(2,0,6); for(i=1;i<=30;i++)
switch(i) { case 1:if(ngay==1)setcolor(4);outtextxy(545,80,"1");setcolor(14); case 2:if(ngay==2)setcolor(4);outtextxy(575,80,"2");setcolor(14); case 3:if(ngay==3)setcolor(4);outtextxy(605,80,"3");setcolor(14); case 4:if(ngay==4)setcolor(4);outtextxy(545,100,"4");setcolor(14); case 5:if(ngay==5)setcolor(4);outtextxy(575,100,"5");setcolor(14); case 6:if(ngay==6)setcolor(4);outtextxy(605,100,"6");setcolor(14); case 7:if(ngay==7)setcolor(4);outtextxy(545,120,"7");setcolor(14); case 8:if(ngay==8)setcolor(4);outtextxy(575,120,"8");setcolor(14); case 9:if(ngay==9)setcolor(4);outtextxy(605,120,"9");setcolor(14); case 10:if(ngay==10)setcolor(4);outtextxy(540,140,"10");setcolor(14); case 11:if(ngay==11)setcolor(4);outtextxy(570,140,"11");setcolor(14); case 12:if(ngay==12)setcolor(4);outtextxy(600,140,"12");setcolor(14); case 13:if(ngay==13)setcolor(4);outtextxy(540,160,"13");setcolor(14); case 14:if(ngay==14)setcolor(4);outtextxy(570,160,"14");setcolor(14); case 15:if(ngay==15)setcolor(4);outtextxy(600,160,"15");setcolor(14); case 16:if(ngay==16)setcolor(4);outtextxy(540,180,"16");setcolor(14); case 17:if(ngay==17)setcolor(4);outtextxy(570,180,"17");setcolor(14); case 18:if(ngay==18)setcolor(4);outtextxy(600,180,"18");setcolor(14); case 19:if(ngay==19)setcolor(4);outtextxy(540,200,"19");setcolor(14); case 20:if(ngay==20)setcolor(4);outtextxy(570,200,"20");setcolor(14); case 21:if(ngay==21)setcolor(4);outtextxy(600,200,"21");setcolor(14); case 22:if(ngay==22)setcolor(4);outtextxy(540,220,"22");setcolor(14); case 23:if(ngay==23)setcolor(4);outtextxy(570,220,"23");setcolor(14); case 24:if(ngay==24)setcolor(4);outtextxy(600,220,"24");setcolor(14); case 25:if(ngay==25)setcolor(4);outtextxy(540,240,"25");setcolor(14); case 26:if(ngay==26)setcolor(4);outtextxy(570,240,"26");setcolor(14); case 27:if(ngay==27)setcolor(4);outtextxy(600,240,"27");setcolor(14); case 28:if(ngay==28)setcolor(4);outtextxy(540,260,"28");setcolor(14); case 29:if(ngay==29)setcolor(4);if(thang!
=2)outtextxy(570,260,"29");setcolor(14); case 30:if(ngay==30)setcolor(4);if(thang!
=2)outtextxy(600,260,"30");setcolor(14);
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 13
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
case 31:if(ngay==31)setcolor(4);if((thang==1)||(thang==3)||(thang==5)||(thang==7)||(thang==8)||(thang==10)||(thang==12))outtextxy(540,280,"31");setcolor(14);
} }void thoigian() { int gio,phut,giay; union REGS tgv,tgr; tgv.h.ah=0x2c; intdos(&tgv,&tgr); gio=tgr.h.ch; phut=tgr.h.cl; giay=tgr.h.dh; gotoxy(70,29);printf(" "); gotoxy(70,29);printf("%d:%d:%d",gio,phut,giay); if(giay<=9){gotoxy(70,29);printf("%d:%d:0%d",gio,phut,giay);} if(phut<=9){gotoxy(70,29);printf("%d:0%d:%d",gio,phut,giay);} if((phut<=9)&&(giay<=9)){gotoxy(70,29);printf("%d:0%d:0%d",gio,phut,giay);} delay(45); }void toado(int x,int y) { gotoxy(15,30);printf("@> <@"); gotoxy(17,30);printf("%d:%d",x,y); delay(45); }void tri() { setviewport(12,35,530,445,1); setlinestyle(0,0,3); setcolor(4); an(); rectangle(200,100,400,280); line(200,130,400,130); line(200,250,400,250); setfillstyle(1,12); floodfill(250,150,4); gotoxy(35,10);printf(" Vo Van Tri "); setcolor(14); outtextxy(230,160,"SVTH : VO VAN TRI" ); outtextxy(230,190,"TRUONG: DHBK DA NANG"); outtextxy(230,210,"LOP : 05T1"); gotoxy(30,20);printf("An enter de ket thuc"); getch();
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 14
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
clearviewport(); hien(); }void exit1() { setviewport(12,35,520,445,1); setcolor(8); rectangle(200,100,400,200); setfillstyle(1,7); floodfill(250,150,8); setcolor(15); settextstyle(3,0,1); outtextxy(225,120,"Ban muon thoat ?"); rectangle(230,150,290,180); rectangle(315,150,380,180); setfillstyle(1,3); floodfill(250,160,15); floodfill(320,160,15); outtextxy(250,150,"Co"); outtextxy(325,150,"Khong"); }void exit2() { int i,x,y,maxcolor,color; while(i<=20000) {i++; x=random(getmaxx());y=random(getmaxy()); maxcolor=getmaxcolor(); color=random(maxcolor); putpixel(x,y,color);delay(1/2); } exit(1); } void Add(List &F)
{ setviewport(12,35,530,445,1); setlinestyle(0,0,3); setcolor(2); an(); rectangle(110,70,480,350); line(110,100,480,100); line(110,325,480,325); setfillstyle(1,6); floodfill(120,80,2); setfillstyle(1,2); floodfill(120,330,2);
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 15
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
settextstyle(0,0,1); setcolor(14); outtextxy(160,335,"Them SV vao DS theo thu tu tang dan."); setcolor(15); settextstyle(1,0,1); outtextxy(140,75,"BANG THEM SV VAO DANH SACH "); List p,before,after; FILE *f; f=fopen("tri.txt","at"); p=new element; gotoxy(21,10);printf("+ Nhap hoten sv : ");gets(y);fputs(y,f);fprintf(f,"
"); gotoxy(21,12);printf("+ Nhap gioi tinh sv: ");gets(g);fputs(g,f);fprintf(f,"
"); gotoxy(21,14);printf("+ Nhap ma sv : ");cin>>x; fprintf(f,"%d ",x); gotoxy(21,16);printf("+ Nam sinh sv : ");cin>>z; fprintf(f,"%d ",z); gotoxy(21,18);printf("+ Nhap diem toan : ");cin>>d1;fprintf(f,"%f
",d1); gotoxy(21,20);printf("+ Nhap diem li : ");cin>>d2;fprintf(f,"%f
",d2); gotoxy(21,22);printf("+ Nhap diem hoa : ");cin>>d3;fprintf(f,"%f
",d3); tb=(d1*2+d2+d3)/4;fprintf(f,"%f ",tb); fprintf(f,"\n"); fclose(f); if(tb<5)strcpy((*p).xl,"yeu"); if((tb>=5)&&(tb<6.5))strcpy((*p).xl,"tb"); if((tb>=6.5)&&(tb<8))strcpy((*p).xl,"kha"); if(tb>=8)strcpy((*p).xl,"gioi"); (*p).ma=x; strcpy((*p).ht,y); (*p).ns=z; strcpy((*p).gt,g); (*p).diem1=d1; (*p).diem2=d2; (*p).diem3=d3; (*p).dtb=tb;
after=F; while((after!=NULL)&&(strcmp((*after).ht,y)<0))
{ before=after; after=(*after).next; } (*p).next=after;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 16
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
if(F==after)F=p; else (*before).next=p;clearviewport();hien();}
void Add1(List &F){ setviewport(12,35,530,445,1); setlinestyle(0,0,3); setcolor(2); an(); rectangle(110,70,480,350); line(110,100,480,100); line(110,325,480,325); setfillstyle(1,7); floodfill(120,80,2); setfillstyle(1,8); floodfill(120,330,2); line(300,325,300,350); settextstyle(1,0,1); setcolor(14); outtextxy(160,325,"Continue"); outtextxy(350,325,"Finish"); setcolor(15); outtextxy(130,75,"BANG NHAP DANH SACH SINH VIEN"); List p,before,after; FILE *f; f=fopen("tri.txt","at"); p=new element; gotoxy(21,10);printf("+ Nhap hoten sv : ");gets(y);fputs(y,f);fprintf(f,"
"); gotoxy(21,12);printf("+ Nhap gioi tinh sv: ");gets(g);fputs(g,f);fprintf(f,"
"); gotoxy(21,14);printf("+ Nhap ma sv : ");cin>>x; fprintf(f,"%d ",x); gotoxy(21,16);printf("+ Nam sinh sv : ");cin>>z; fprintf(f,"%d ",z); gotoxy(21,18);printf("+ Nhap diem toan : ");cin>>d1;fprintf(f,"%8.2f
",d1); gotoxy(21,20);printf("+ Nhap diem li : ");cin>>d2;fprintf(f,"%8.2f
",d2); gotoxy(21,22);printf("+ Nhap diem hoa : ");cin>>d3;fprintf(f,"%8.2f
",d3); tb=(d1*2+d2+d3)/4; fprintf(f,"%8.2f ",tb); fprintf(f,"\n");
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 17
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
fclose(f); if(tb<5)strcpy((*p).xl,"yeu"); else if((tb>=5)&&(tb<6.5))strcpy((*p).xl,"tb"); else if((tb>=6.5)&&(tb<8))strcpy((*p).xl,"kha"); else if(tb>=8)strcpy((*p).xl,"gioi"); (*p).ma=x; strcpy((*p).ht,y); (*p).ns=z; strcpy((*p).gt,g); (*p).diem1=d1; (*p).diem2=d2; (*p).diem3=d3; (*p).dtb=tb;
after=F; while((after!=NULL)&&(strcmp((*after).ht,y)<0))
{ before=after; after=(*after).next; } (*p).next=after; if(F==after)F=p; else (*before).next=p;hien();}
void Find(List F) { setviewport(12,35,530,445,1);
setlinestyle(0,0,3); setcolor(3); an(); rectangle(110,70,480,355); line(110,100,480,100); line(110,325,480,325); setfillstyle(1,7); floodfill(120,80,3); rectangle(120,330,470,350); setfillstyle(1,8); floodfill(118,328,3); settextstyle(1,0,1); setcolor(4); outtextxy(160,75,"BANG NOI DUNG SING VIEN");
gotoxy(18,24);printf("->Nhap ten SV can tim:"); gets(y); List p; p=F;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 18
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
while((p!=NULL)&&(strcmp((*p).ht,y))!=0) p=(*p).next;
if((p!=NULL)&&(strcmp((*p).ht,y)==0)) { gotoxy(21,10);cout<<"+ Ma SV la : "<<(*p).ma; gotoxy(21,11);cout<<"+ Ho ten : "<<(*p).ht; gotoxy(21,12);cout<<"+ Gioi tinh: "<<(*p).gt; gotoxy(21,13);cout<<"+ Nam sinh : "<<(*p).ns; gotoxy(21,14);cout<<"+ Diem toan: "<<(*p).diem1; gotoxy(21,15);cout<<"+ Diem ly : "<<(*p).diem2; gotoxy(21,16);cout<<"+ Diem hoa : "<<(*p).diem3; gotoxy(21,17);printf("+ Diem tb
:%8.2f",(*p).dtb);//cout<<"+ Diem tb : "<<(*p).dtb; gotoxy(21,18);cout<<"+ Xep loai : "<<(*p).xl; }
else {gotoxy(21,10);cout<<"SV nay khong co trong dang sach.";} getch(); clearviewport(); hien(); }void Delete(List &F) { setviewport(12,35,530,445,1);
setlinestyle(0,0,3); setcolor(9); ("BANG TRU SV RA KHOI DS"); gotoxy(23,18);printf("Loai SV nay ra khoi DS."); an(); rectangle(120,70,400,255); line(120,100,400,100); setfillstyle(1,10); floodfill(130,80,9); line(120,230,400,230); setfillstyle(1,9); floodfill(130,235,9); settextstyle(1,0,1); setcolor(4); outtextxy(130,75,"BANG LOAI SV KHOI DS"); settextstyle(0,0,1); setcolor(15); outtextxy(130,240,"Loai sinh vien nay khoi danh sach.");
List before,t; gotoxy(22,11);printf(" Nhap ten SV can xoa:\n"); gotoxy(22,12);printf("->");gets(y); p=F;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 19
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
while((p!=NULL)&&(strcmp((*p).ht,y))!=0) p=(*p).next;
if((p!=NULL)&&(strcmp((*p).ht,y)==0))t=p;if(p==NULL)goto nhan1;
p=F; while((p!=NULL)&&(p!=t))
{ before=p;p=(*p).next;
} if(p!=NULL)
{ if(F==t)F=(*F).next; else (*before).next=(*t).next; }
delete(t); gotoxy(22,14);printf("->Mot SV da duoc xoa khoi DS"); goto nhan2; nhan1: gotoxy(22,14);printf("->SV khong co trong DS"); nhan2: getch(); clearviewport(); hien(); } void Fix(List &F) { setviewport(12,35,530,445,1);
setlinestyle(0,0,3); setcolor(10); an(); rectangle(20,50,510,360); line(20,80,510,80); setfillstyle(1,10); floodfill(30,70,10); line(20,100,510,100); setfillstyle(1,11); floodfill(30,90,10); line(250,80,250,320); line(20,320,510,320); setcolor(8); rectangle(30,330,500,350); rectangle(20,320,510,360); setfillstyle(1,8); floodfill(25,325,8); setcolor(4);
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 20
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
outtextxy(80,80,"Old struct"); outtextxy(320,80,"New struct"); settextstyle(1,0,1); setcolor(14); outtextxy(80,55,"BANG SUA DOI NOI DUNG SINH VIEN"); setcolor(10); rectangle(30,330,500,350); rectangle(20,320,510,360);
List before,t; gotoxy(9,24);printf("->Nhap ten can thay doi:");gets(y); p=F; while((p!=NULL)&&(strcmp((*p).ht,y))!=0)
p=(*p).next;if((p!=NULL)&&(strcmp((*p).ht,y)==0))t=p;if(p==NULL)goto nhan1; gotoxy(6,11);cout<<"+ Ho ten : "<<(*p).ht; gotoxy(6,12);cout<<"+ Gioi tinh: "<<(*p).gt; gotoxy(6,13);cout<<"+ Ma SV la : "<<(*p).ma; gotoxy(6,14);cout<<"+ Nam sinh : "<<(*p).ns; gotoxy(6,15);cout<<"+ Diem toan: "<<(*p).diem1; gotoxy(6,16);cout<<"+ Diem ly : "<<(*p).diem2; gotoxy(6,17);cout<<"+ Diem hoa : "<<(*p).diem3; gotoxy(6,18);printf("+ Diem tb :%8.2f",(*p).dtb); gotoxy(6,19);cout<<"+ Xep loai : "<<(*p).xl; gotoxy(34,11);printf("+ Nhap hoten sv : ");gets(y); gotoxy(34,12);printf("+ Gioi tinh sv : ");gets(g); gotoxy(34,13);printf("+ Nhap ma sv : ");cin>>x; gotoxy(34,14);printf("+ Nam sinh sv : ");cin>>z; gotoxy(34,15);printf("+ Nhap diem toan: ");cin>>d1; gotoxy(34,16);printf("+ Nhap diem li : ");cin>>d2; gotoxy(34,17);printf("+ Nhap diem hoa : ");cin>>d3; tb=(d1*2+d2+d3)/4; if(tb<5)strcpy((*p).xl,"yeu"); else if((tb>=5)&&(tb<6.5))strcpy((*p).xl,"tb"); else if((tb>=6.5)&&(tb<8))strcpy((*p).xl,"kha"); else if(tb>=8)strcpy((*p).xl,"gioi"); (*p).ma=x; strcpy((*p).ht,y); (*p).ns=z; strcpy((*p).gt,g); (*p).diem1=d1; (*p).diem2=d2; (*p).diem3=d3;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 21
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
(*p).dtb=tb; gotoxy(34,18);printf("+ Diem tb :%8.2f",(*p).dtb); gotoxy(34,19);cout<<"+ Xep loai : "<<(*p).xl;goto nhan2;nhan1: gotoxy(9,11);printf("->SV khong co trong DS");nhan2: getch(); clearviewport(); hien();
} void getlist(List &F) { int t,muose_x,muose_y; setviewport(12,35,530,445,1); setlinestyle(0,0,3); setcolor(2); an(); rectangle(110,70,480,350); line(110,100,480,100); line(110,325,480,325); setfillstyle(1,7); floodfill(120,80,2); setfillstyle(1,8); floodfill(120,330,2); line(300,325,300,350); setcolor(15); outtextxy(130,75,"BANG NHAP DANH SACH SINH VIEN"); F=NULL; Add1(F); hien(); }
Thư viện gt1.h
#include<conio.h>#include<stdio.h>#include<dos.h>#include<graphics.h>#include<stdlib.h>void gt(){ setviewport(12,35,530,445,1); int i,j=70,k=0,h=500,t=360; setbkcolor(1); for(i=30;i<=500;i++){ k=i;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 22
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
setcolor(7); line(i,j,i,j); setcolor(8); line(i,j+4,i,j+4); setcolor(15); setlinestyle(0,0,2); line(i,j+2,i,j+2);
setcolor(8); line(h,270+j,h,270+j); setcolor(7); line(h,270+j+4,h,270+j+4); setcolor(15); setlinestyle(0,0,2); line(h,270+j+2,h,270+j+2);
if(k<=370) { setcolor(7); line(j,k+10,j,k+10); setcolor(8); line(j+4,k+10,j+4,k+10); setcolor(15); setlinestyle(0,0,1); line(j+2,k+10,j+2,k+10);
setcolor(8); line(j+400,t+20,j+400,t+20); setcolor(7); line(400+j+4,t+20,400+j+4,t+20); setcolor(15); setlinestyle(0,0,1); line(400+j+2,t+20,400+j+2,t+20); } h--;t--; delay(5);
setcolor(8); }
setfillstyle(1,15); floodfill(250,100,8); for(i=100;i>=90;i--){ setcolor(14);
outtextxy(220,i,"DAI HOC DA NANG"); outtextxy(185,i+10,"TRUONG DAI HOC BACH
KHOA");
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 23
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
outtextxy(185,i+20,"KHOA CONG NGHE THONG TIN");
outtextxy(250,i+30,"oo0oo"); delay(100); setcolor(9); outtextxy(220,i,"DAI HOC DA NANG"); outtextxy(185,i+10,"TRUONG DAI HOC BACH
KHOA"); outtextxy(185,i+20,"KHOA CONG NGHE THONG
TIN"); outtextxy(250,i+30,"oo0oo"); if(i==90)setcolor(14); outtextxy(220,i,"DAI HOC DA NANG"); outtextxy(185,i+10,"TRUONG DAI HOC BACH
KHOA"); outtextxy(185,i+20,"KHOA CONG NGHE THONG
TIN"); outtextxy(250,i+30,"oo0oo"); }
for(i=90;i<=140;i++){ settextstyle(4,0,4);setcolor(12);outtextxy(i,150,"DO AN MON HOC");delay(50);setcolor(15);outtextxy(i,150,"DO AN MON HOC");if(i==140)setcolor(12);outtextxy(i,150,"DO AN MON HOC");}
for(i=90;i<=170;i++){ settextstyle(0,0,1);setcolor(10);outtextxy(i+30,200,"DANH SACH LIEN KET");delay(20);setcolor(15);outtextxy(i+30,200,"DANH SACH LIEN KET");if(i==170)setcolor(10);outtextxy(i+30,200,"DANH SACH LIEN KET");}
for(i=90;i<=300;i++){ settextstyle(0,0,1);setcolor(4);outtextxy(i,250,"Gvhd: P.C.TUNG");delay(20);setcolor(15);outtextxy(i,250,"Gvhd: P.C.TUNG");
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 24
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
if(i==300)setcolor(4);outtextxy(i,250,"Gvhd: P.C.TUNG");
} for(i=90;i<=300;i++){ settextstyle(0,0,1);
setcolor(4);outtextxy(i,270,"Svth: VO VAN TRI");delay(20);setcolor(15);outtextxy(i,270,"Svth: VO VAN TRI");
if(i==300)setcolor(4);outtextxy(i,270,"Svth: VO VAN TRI");
} for(i=90;i<=300;i++){ settextstyle(0,0,1);
setcolor(4);outtextxy(i,290,"Lop : 05t1");delay(20);setcolor(15);outtextxy(i,290,"Lop : 05t1");
if(i==300)setcolor(4);outtextxy(i,290,"Lop : 05t1");
} for(i=330;i>=325;i--){ settextstyle(0,0,1);
setcolor(8);outtextxy(180,i,"An Enter de ket thuc ");delay(20);setcolor(15);outtextxy(180,i,"An Enter de ket thuc ");
if(i==325)setcolor(8);outtextxy(180,i,"An Enter de ket thuc !");
}getch();
clearviewport(); }
Thư viện mouse.h#include<conio.h>#include<stdio.h>#include<dos.h>#define nt 1;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 25
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
#define np 2;#define ng 3;
void khoi_tao() { union REGS v,r; v.x.ax=0x0000; int86(0x33,&v,&r); }void hien() { union REGS v,r; v.x.ax=0x0001; int86(0x33,&v,&r); }void an() { union REGS v,r; v.x.ax=0x0002; int86(0x33,&v,&r); }int vi_tri(int *x,int *y) { union REGS v,r;
v.x.ax=0x0003; int86(0x33,&v,&r); *x=r.x.cx; *y=r.x.dx; return(r.x.bx); }void di_chuyen(int x,int y) { union REGS v,r; v.x.ax=0x0004; v.x.cx=x; v.x.dx=y; int86(0x33,&v,&r); }void gh_ngang(int cot_trai,int cot_phai) { union REGS v,r; v.x.ax=0x0007; v.x.cx=cot_trai; v.x.dx=cot_phai; int86(0x33,&v,&r); }void gh_doc(int dong_tren,int dong_duoi) { union REGS v,r; v.x.ax=0x0008;
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 26
ĐỒ ÁN MÔN HỌC GVHD : Phan Chí Tùng
v.x.cx=dong_tren; v.x.dx=dong_duoi; int86(0x33,&v,&r); }int ghtd(int x, int y,int cot,int hang) { int result;
result=0; if((x>= cot)&&(x<= cot+30)&&(y>=hang)&&(y<=hang+30 ))
result =1; return(result);}
¶.Hướng dẫn sử dụng chương trình : Mô hình quản lý danh sách sinh viên dùng đồ họa được mô phỏng với giao diện trực quan dễ sử dụng .Khi sử dụng chương trình chỉ cần copy 3 tệp tin sau và thả vào thư mục include trong chương trình C : - vantri9.h - gt1.h -mouse.h Khi chạy chương trình , kích chuột phải để hiện lên bảng thực đơn tùy chọn công việc cần thực hiện .
¶.Kết luận :
Bài toán quản lý danh sách sinh viên gồm mã, họ tên, ngày sinh, giới tính, điểm từng môn, điểm trung bình, xếp loại. Chương trình có khả năng thêm, bớt, sửa chữa, tìm kiếm, thống kê dữ liệu dùng giao diện đồ họa trực quan đã được giải quyết Tuy bài toán đã thành công tốt đẹp nhưng vẫn chưa thật sự hoàn chỉnh và còn rất nhiều sai sótMong nhận được sự giúp đở , đóng góp ý kiến của thầy cô và các bạn để chương trình hoàn thiện hơn. Đà Nẵng, Ngày 10/11/2007 Sinh Viên Thực Hiện : Võ Văn Trí Nguyễn Thanh Trung Lớp : 05T1
SVTH :Võ Văn Trí –Nguyễn Thanh Trung Lớp 05T1 Môn: Cấu Trúc Dữ Liệu 27