📄 bfs.bak
字号:
nhaptufile();
}
void gd_matranke()
{
gd();
indothi(sodinh,cohuong,canh);
}
void gd_dothi()
{
setfillstyle(1,LIGHTBLUE);
bar(0,0,getmaxx(),getmaxy());
venut(20,455,90,470," Menu");
venut(110,455,180,470," BFSKDQ");
venut(200,455,270,470," BFSDQ");
venut(290,455,360,470," DFS");
venut(380,455,460,470,"LienThong");
venut(480,455,550,470," Back");
vedtlenmanhinh(cohuong);
show_mouse();
do{
ctrl_button();
while(button==1)
{
ctrl_button();
if(x>=110 && x<=180 && y>=455 && y<=470)
{
hide_mouse();
venut1(110,455,180,470," BFSKDQ");
delay(150);
venut(110,455,180,470," BFSKDQ");
BFSaction(1);
show_mouse();
break;
}
if(x>=200 && x<=270 && y>=455 && y<=470)
{
hide_mouse();
venut1(200,455,270,470," BFSDQ");
delay(150);
venut(200,455,270,470," BFSDQ");
BFSaction(0);
show_mouse();
break;
}
if(x>=290 && x<=360 && y>=455 && y<=470)
{
hide_mouse();
venut1(290,455,360,470," DFS");
delay(150);
venut(290,455,360,470," DFS");
BFSaction(2);
show_mouse();
break;
}
if(x>=380 && x<=460 && y>=455 && y<=470)
{
hide_mouse();
venut1(380,455,460,470,"LienThong");
delay(150);
venut(380,455,460,470,"LienThong");
// BFSaction();
show_mouse();
break;
}
if(x>=20 && x<=100 && y>=455 && y<=470)
{
hide_mouse();
venut1(20,455,100,470," Menu");
delay(150);
venut(20,455,100,470," Menu");
back_interface();
show_mouse();
control_program();
break;
}
if(x>=480 && x<=550 && y>=455 && y<=470)
{
hide_mouse();
venut1(480,455,550,470," Back");
delay(150);
venut(480,455,550,470," Back");
start();
show_mouse();
break;
}
}
}while(!kbhit());
}
void gd_duyet()
{
gd();
vedtlenmanhinh(cohuong);
BFSaction(1);
}
//****************************************
void designers()
{
int i;
setfillstyle(1,LIGHTBLUE);
bar(0,0,getmaxx(),getmaxy());
setcolor(14);
for(i=0;i<5;i++)
{
rectangle(i,i,getmaxx()-i,getmaxy()-i);
}
bar(150,150,getmaxx()-178,getmaxy()-150);
setfillstyle(2,WHITE);
rectangle(150,150,getmaxx()-179,getmaxy()-151);
setcolor(WHITE);
outtextxy(220,180,"NHUNG NGUOI THUC HIEN");
setcolor(YELLOW);
outtextxy(163,200,"+ DOAN MINH HOAI - 05110050 ");
outtextxy(163,220,"+ TO XUAN CHIEN - 05110013 ");
outtextxy(163,240,"+ LE MINH VUONG - 05110165 ");
outtextxy(163,260,"+ HAN CONG PHONG - 05110099 ");
outtextxy(163,280,"+ TRAN DINH LONG - 05110073 ");
venut(23,460,70,475,"Back");
}
void interface()
{
setfillstyle(1,LIGHTBLUE);
bar(0,0,getmaxx(),getmaxy());
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(LIGHTGREEN);
outtextxy(250,14,"DO AN MON HOC");
outtextxy(205,40,"MON LY THUYET DO THI");
outtextxy(280,100,"DE TAI ");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(180,120,"DUYET DO THI THEO CHIEU RONG");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(245,260,"Menu chuong trinh");
setlinestyle(DASHED_LINE,SOLID_LINE,NORM_WIDTH);
setcolor(12);
line(120,70,500,70);
setcolor(YELLOW);
rectangle(190,230,430,430);
venut(270,300,350,315," Start");
venut(270,325,350,340," Help");
venut(270,350,350,365,"Designers");
venut(270,375,350,390," Exit");
}
void interface1()
{
setfillstyle(1,LIGHTBLUE);
bar(0,0,getmaxx(),getmaxy());
settextstyle(TRIPLEX_FONT,HORIZ_DIR,2);
setcolor(LIGHTGREEN);
outtextxy(260,14,"DO AN MON HOC");
outtextxy(220,40,"MON LY THUYET DO THI");
outtextxy(280,100,"MUC DICH ");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
outtextxy(180,120,"MO PHONG CAC THAO TAC TREN DO THI");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
outtextxy(260,260,"Hay Lua Chon");
setlinestyle(DASHED_LINE,SOLID_LINE,NORM_WIDTH);
setcolor(12);
line(120,70,500,70);
setcolor(YELLOW);
rectangle(190,230,430,430);
venut(270,300,370,315,"Duyet Do Thi");
venut(270,325,370,340," Hamilton");
venut(270,350,370,365," Menu");
venut(270,375,370,390," Exit");
control_program1();
}
//********************************************************
//ham dieu khien menu
void control_program()
{
show_mouse();
do
{
ctrl_button();
while(button==1)
{
ctrl_button();
if(x>=270&&x<=350&&y>=300&&y<=315)
{
hide_mouse();
venut1(270,300,350,315," Start");
delay(150);
interface1();
show_mouse();
back_start();
}
if(x>=270&&x<=350&y>=325&&y<=340)
{
hide_mouse();
venut1(270,325,350,340," Help");
delay(150);
reset_mouse();
help();
show_mouse();
back();
}
if(x>=270&&x<=350&&y>=350&&y<=365)
{
hide_mouse();
venut1(270,350,350,365,"Designers");
delay(150);
reset_mouse();
designers();
show_mouse();
back();
}
if(x>=270&&x<=350&&y>=375&&y<=390)
{
hide_mouse();
venut1(270,375,350,390," Exit");
delay(150);
shutdow();
}
}
}
while(!kbhit());
}
void control_program1()
{
show_mouse();
do
{
ctrl_button();
while(button==1)
{
ctrl_button();
if(x>=270&&x<=370&&y>=300&&y<=315)
{
hide_mouse();
venut1(270,300,370,315,"Duyet Do Thi");
delay(150);
start();
show_mouse();
back_start();
}
if(x>=270&&x<=370&y>=325&&y<=340)
{
hide_mouse();
venut1(270,325,370,340," Hamilton");
delay(150);
reset_mouse();
gd_hamilton();
show_mouse();
back();
}
if(x>=270&&x<=370&&y>=350&&y<=365)
{
hide_mouse();
venut1(270,350,370,365," Menu");
delay(150);
reset_mouse();
back_interface();
show_mouse();
control_program();
back();
}
if(x>=270&&x<=370&&y>=375&&y<=390)
{
hide_mouse();
venut1(270,375,370,390," Exit");
delay(150);
shutdow();
}
}
}
while(!kbhit());
}
//**************************************************************
//dieu khien menu start
void control_program_start()
{
show_mouse();
do
{
ctrl_button();
while(button==1)
{
ctrl_button();
if(x>=230&&x<=310&&y>=15&&y<=30)
{
hide_mouse();
venut1(230,15,310,30,"Ban phim");
delay(150);
venut(230,15,310,30,"Ban phim");
gd_banphim();
show_mouse();
break;
}
if(x>=330&&x<=410&&y>=15&&y<=30)
{
hide_mouse();
venut1(330,15,410,30," File");
delay(150);
venut(330,15,410,30," File");
gd_file();
show_mouse();
break;
}
if(x>=10&&x<=100&y>=105&&y<=120)
{
if(sodinh==0)
{
hide_mouse();
gd();
venut1(10,105,100,120,"Ma tran ke");
delay(150);
venut(10,105,100,120,"Ma tran ke");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(150,200,"Xin loi, Ban chua nhap do thi!");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
show_mouse();
break;
}
else
{
hide_mouse();
venut1(10,105,100,120,"Ma tran ke");
delay(150);
venut(10,105,100,120,"Ma tran ke");
gd_matranke();
show_mouse();
break;
}
}
if(x>=10&&x<=100&&y>=130&&y<=145)
{
if(sodinh==0)
{
hide_mouse();
gd();
venut1(10,130,100,145," Do thi");
delay(150);
venut(10,130,100,145," Do thi");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(150,200,"Xin loi, Ban chua nhap do thi!");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
show_mouse();
break;
}
else
{
hide_mouse();
venut1(10,130,100,145," Do thi");
delay(150);
venut(10,130,100,145," Do thi");
gd_dothi();
show_mouse();
break;
}
}
if(x>=10&&x<=100&&y>=155&&y<=170)
{
/*if(sodinh==0)
{
hide_mouse();
gd();
venut1(10,155,100,170," Duyet");
delay(150);
venut(10,155,100,170," Duyet");
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
outtextxy(150,200,"Xin loi, Ban chua nhap do thi!");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
show_mouse();
break;
}*/
//else
// {
hide_mouse();
venut1(10,155,100,170," Hamilton");
delay(150);
venut(10,155,100,170," Hamitlon");
gd_hamilton();
vechuback();
back_start();
show_mouse();
break;
// }
}
if(x>=10&&x<=100&&y>=180&&y<=195)
{
hide_mouse();
venut1(10,180,100,195," Menu");
delay(150);
// cleardevice();
interface1();
show_mouse();
control_program1();
}
}
}
while(!kbhit());
}
//////////////////// Phan help trong menu ////////////
void help()
{
basic1(WHITE,LIGHTBLUE);
settextstyle(3,DEFAULT_FONT,2);
setcolor(LIGHTBLUE);
outtextxy(150,10,"Huong Dan Su Dung Chuong Trinh");
settextstyle(SMALL_FONT,DEFAULT_FONT,4);
setcolor(RED);
outtextxy(25,40,"+ Nhap");
setcolor(LIGHTBLUE);
outtextxy(37,54,"Ban dung ban phim de nhap du lieu");
outtextxy(37,68,"So dinh nhap khong qua 15 dinh va ma tran nhap o dang ma tran ke [0] va [1]");
setcolor(GREEN);
outtextxy(37,82,"Vi du");
setcolor(LIGHTBLUE);
outtextxy(37,96,"So dinh: 3");
outtextxy(37,110,"Ma tran ke nhap co dang");
setcolor(LIGHTBLUE);
outtextxy(50,124,"0 1 0");
outtextxy(50,138,"1 0 1");
outtextxy(50,152,"0 1 0");
setcolor(GREEN);
outtextxy(37,166,"Sau khi nhap xong ma tran ban lam theo chi dan tren man hinh de tien hanh ve do thi");
setcolor(RED);
outtextxy(25,180,"+ Doc File");
setcolor(LIGHTBLUE);
outtextxy(37,194,"Ban dung ban phim de nhap duong dan");
setcolor(GREEN);
outtextxy(37,208,"Vi du");
setcolor(LIGHTBLUE);
outtextxy(37,222,"Gia su File can doc co ten la baitap.txt nam trong o dia C");
outtextxy(37,236,"Duong dan ban se nhap la");
outtextxy(37,250,"C:\\baitap.txt");
setcolor(GREEN);
outtextxy(37,264,"Sau khi nhap xong ma tran ban lam theo chi dan tren man hinh de tien hanh ve do thi");
setcolor(RED);
outtextxy(25,278,"+ Giai Thuat");
setcolor(LIGHTBLUE);
outtextxy(37,292,"Sau khi da nhap xong du lieu cho may ban lam theo cac buoc huong dan cua chuong trinh");
outtextxy(37,306,"Luu y neu du lieu chua duoc nhap hoac nhap sai thi may se bao loi");
outtextxy(37,320,"Ban khong duoc nhap nut bat dau lon hon so dinh da nhap neu da nhap thi may yeu cau nhap lai");
outtextxy(37,334,"Nut bat dau ban phai nhap neu khong nhap may se thong bao loi yeu cau nhap lai ");
outtextxy(37,348,"Moi dinh cua do thi sau khi duyet xong se sang len");
outtextxy(37,362,"Dinh bat dau duoc to mau do sau khi giai thuat hoan thanh");
outtextxy(37,376,"Sau khi giai thuat BSF ket thuc ban se thay ket qua cua qua trinh giai thuat o phia duoi man hinh");
setcolor(GREEN);
outtextxy(37,390,"* Nhom thuc hien xin chan thanh cam on su giup do cua thay va cac ban ");
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
venut(23,460,70,475,"Back");
}
//////////////////////// Phan than chuong trinh ////////////////////////////////
//////////////// Hai ham ho tro cho in va nhap /////////////
void forprintf(int x,int y,char *s,int color)
{
setcolor(color);
outtextxy(x,y,s);
}
void forscanf(int x,int y,char *s)
{
int i=0;
char ch[2];
ch[1]=0;
while(1)
{
x+=7;
ch[0]=getch();
if(ch[0]==13)
break;
forprintf(x,y,ch,LIGHTRED);
s[i]=ch[0];
++i;
}
s[i]=0;
}
//////////////////// Kiem tra do thi nhap vao //////////////////////////////
void indothi(int n,int h,int a[][max1])
{
char tam[1];
char tam1[2];
int c,b,a1,b1;
char s1[2],s2[2];
gd();
setcolor(WHITE);
outtextxy(140,50,"DU LIEU DOC DUOC ");
outtextxy(125,70," So dinh cua do thi la : ");
itoa(n,tam,10);
forprintf(325,70,tam,WHITE);
setcolor(WHITE);
if(h==1) outtextxy(125,90,"Do thi co huong ");
else outtextxy(125,90,"Do thi vo huong ");
kiemtra(n,a);
outtextxy(140,150," MA TRAN KE TUONG UNG ");
b=b1=170;
for(i=1;i<=n;i++)
{
c=a1=140;
itoa(i,s1,10);
setcolor(YELLOW);
outtextxy(c,b1+15,s1);
for(j=1;j<=n;j++)
{
itoa(j,s2,10);
setcolor(RED);
itoa(a[i][j],tam1,10);
outtextxy(a1+22,b1+14,tam1);
setcolor(YELLOW);
outtextxy(a1+20,b,s2);
a1+=30;
}
setcolor(YELLOW);
outtextxy(c,b1+15,s1);
b1+=15;
}
setcolor(GREEN);
}
int nhapsodinh(int &sodinh)
{
int dinh;
char chon;
printf("\nNhap vao so dinh cua do thi (1->15): ");
scanf("%d",&dinh);
fflush(stdin);
chon=getchar();
while(((dinh<1)||(dinh>15))||(isalpha(chon)))
{
printf("\nNhap so dinh sai - Nhap lai ");
printf("\nSo dinh cua do thi (1->15) : ");
scanf("%d",&dinh);
fflush(stdin);
chon=getchar();
}
sodinh=dinh;
return sodinh;
}
int nhaphuong(int &cohuong)
{
int huong;
char chon;
printf("\nNhap vao huong cua do thi");
printf("\nco huong(1) - vo huong(0): ");
fflush(stdin);
chon=getchar();
huong=(int)chon;
while((huong!=48)&&(huong!=49))
{
printf("\n\nNhap sai - nhap lai ");
printf("\nDo thi co huong(1) - vo huong(0) : ");
fflush(stdin);
chon=getchar();
huong=(int)chon;
}
huong=(char)huong;
if(huong==48) huong=0;
else huong=1;
cohuong=huong;
return cohuong;
}
/////////////////////////// Nhap tren ma tran //////////////////////////////
void drawgraph(int a[][min],int n)
{
char t[50];
setcolor(LIGHTBLUE);
for(i=1;i<=n;i++)
{
nut[i].dx=i*30+25;
nut[i].dy=abs(random(getmaxy()-79))+20;
circle(nut[i].dx-2,nut[i].dy,3);
sprintf(t,"%d",i);
outtextxy(nut[i].dx+5,nut[i].dy,t);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if((a[i][j]&&a[j][i])==1)
{
line(nut[i].dx-2,nut[i].dy,nut[j].dx-2,nut[j].dy);
}
}
void basic1(int color1,int color2)
{
int i;
setfillstyle(1,color1);
bar(0,0,getmaxx(),getmaxy());
setcolor(color2);
setlinestyle(0,0,3);
rectangle(0+1,0+1,getmaxx()-1,getmaxy()-1);
}
void input(int &n,int &h,int a[][max1])
{
int i,j,c,b,a1,b1;
char dinh[2],s1[2],s2[2],tam[1],h1[1];
char s[25];
int tam1;
char temp[2],temp1[2];
char temp2[2];
strcpy(s,"c:\\output.txt");
gd();
setcolor(LIGHTRED);
outtextxy(120,55,"NHAP DO THI TU BAN PHIM");
forprintf(150,75,"Nhap so dinh:",LIGHTRED);
forscanf(250,75,dinh);
n=atoi(dinh);
while(n<1||n>15)
{
delay(200);
gd();
setcolor(LIGHTRED);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -