NHÓM 3 CTIM
Bạn chưa đăng nhập.
Mời bạn đăng nhập. Nếu bạn chưa có tài khoản thì click "đăng ký" để tạo tài khoản mới.
NHÓM 3 CTIM
Bạn chưa đăng nhập.
Mời bạn đăng nhập. Nếu bạn chưa có tài khoản thì click "đăng ký" để tạo tài khoản mới.
NHÓM 3 CTIM
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

NHÓM 3 CTIM

Thành công bắt đầu từ thất bại
 
Trang ChínhGalleryTìm kiếmLatest imagesĐăng kýĐăng Nhập

 

 Phương pháp chèn trực tiếp (đồ họa)

Go down 
Tác giảThông điệp
LuckyStar
Rìu Bạc
Rìu Bạc
LuckyStar


Tổng số bài gửi : 139
Điểm Thưởng : 5319
Số lần được cám ơn : 2
Join date : 13/10/2010
Age : 35
Đến từ : Trường cao đẳng Công Nghệ và Quản Trị Doanh Nghiệp

Phương pháp chèn trực tiếp (đồ họa) Empty
Bài gửiTiêu đề: Phương pháp chèn trực tiếp (đồ họa)   Phương pháp chèn trực tiếp (đồ họa) I_icon_minitimeThu Oct 14, 2010 6:31 pm

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<dos.h>
#include<math.h>
#include<ctype.h>
#define MAX 10
#define DONG 10
#define DELAY 300
int a[MAX],b[MAX],c[MAX],A[MAX];
int cot=(80-5*MAX)/2;
void menutanggiam(char &cl)
{
char c;
int i,j;
//thao tac di chuyen chuot
i=1,j=24;
gotoxy(1,23);printf("CHON HUONG SAP XEP");
gotoxy(1,24);printf("Sap xep tang dan.");
gotoxy(1,25);printf("Sap xep giam dan.");
do
{
gotoxy(i,j);
switch(j)
{
case 24:textcolor(WHITE+BLINK);cprintf("Sap xep tang dan.");break;
case 25:textcolor(WHITE+BLINK);cprintf("Sap xep giam dan.");break;
}
c=getch();
if(c==0||c==13)
{
if(c==0) c=getch();
if(c==72)
{
if(j==25)
{
gotoxy(1,25);textcolor(11);cprintf("Sap xep giam dan.");
j--;
}
}
if(c==80)
{
if(j==24)
{
gotoxy(1,24);textcolor(11);cprintf("Sap xep tang dan.");
j++;
}
}
if(c==13)
{
if(j==24)
{
cl='T';
gotoxy(1,23);textcolor(YELLOW);cprintf("DANG SAP XEP ");
gotoxy(1,24);textcolor(11);cprintf(" ");
gotoxy(1,25);cprintf("Dang sap xep tang dan.");
}
if(j==25)
{
cl='G';
gotoxy(1,23);textcolor(YELLOW);cprintf("DANG SAP XEP ");
gotoxy(1,24);textcolor(11);cprintf(" ");
gotoxy(1,25);cprintf("Dang sap xep giam dan.");
}
break;
}
}
if(c==27)
{
cl=27;break;
}
}while(c!=13&&c!=27);
}

void doicho(int i,int j) // 2 vi tri cung do cao
{
int xi=cot+2+i*5;
int yi=DONG+1;
int xj=cot+2+j*5;
int yj=DONG+1;
int xdest=xj;
int k;
textcolor(YELLOW);
for(k=0;k<2;k++)
{
gotoxy(xi,yi--);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
gotoxy(xj,yj++);cprintf(" ");
gotoxy(xj,yj);cprintf("%2d",a[j]);
delay(DELAY);
}
while(xi<xdest)
{
gotoxy(xi++,yi);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
gotoxy(xj--,yj);cprintf(" ");
gotoxy(xj,yj);cprintf("%2d",a[j]);
delay(DELAY);
}
for(k=0;k<2;k++)
{
gotoxy(xi,yi++);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
gotoxy(xj,yj--);cprintf(" ");
gotoxy(xj,yj);cprintf("%2d",a[j]);
delay(DELAY);
}
xdest=a[i];
a[i]=a[j];
a[j]=xdest;
}
void in_bien_i(int i,int d,char c)
{
gotoxy(cot+(i-1)*5+1,d-3);textcolor(BLACK);cprintf(" ");
gotoxy(cot+(i)*5+1,d-3);textcolor(WHITE+BLINK);cprintf("%c",c);//// mui ten chi xuong.
}
void xoa_bien_i(int i,int d)
{
gotoxy(cot+(i)*5+1,d-3);textcolor(BLACK);cprintf(" ");
}
void in_bien_j(int j,int d,char c)
{
gotoxy(cot+(j-1)*5+1,d+5);textcolor(BLACK);cprintf(" ");
gotoxy(cot+(j)*5+1,d+5);textcolor(WHITE+BLINK);cprintf("%c",c);//// mui ten chi len.
}
void xoa_bien_j(int j,int d)
{
gotoxy(cot+(j)*5+1,d+5);textcolor(BLACK);cprintf(" ");
}
void giaodien(char *s,int dong)/////dong chi chieu cao
{
char khung='Ý';
int i,j;
/////xoa man hinh////
textmode(C80);
textattr(14);
textcolor(YELLOW);
clrscr();
///in dong tieu de
gotoxy((80-strlen(s))/2,2);cprintf("%s",s);
/////khoi tao mang can sap ngau nhien//
randomize();
for(i=0;i<MAX;i++)
{
a[i]=random(100);
}
/////in ra man hinh////
textcolor(WHITE);
for(i=0;i<3;i++)
{
gotoxy(cot,dong+i);cprintf("%c",khung);
}
for(j=0;j<MAX;j++)
{
textcolor(WHITE);
textcolor(11);
gotoxy(cot+j*5+2,dong+1);cprintf("%2d",a[j]);
textcolor(WHITE);
for(i=0;i<3;i++)
{
gotoxy(cot+(j+1)*5,dong+i);cprintf("%c",khung);
}
}
for(i=0;i<3;i++)
{
gotoxy(cot+MAX*5,dong+i);cprintf("%c",khung);
}
//in cau thong bao thuc hien
textcolor(YELLOW);
gotoxy(1,dong-4);cprintf("Bien i");
}
//ham dung rieng cho insertion sort
void rangoaidoi(int i,int d,int &x)
{
int xi=cot+2+i*5; //chuyen a[i] ra ngoai de cho
int yi=d+1; //cho tim cho chen vao mang a
int k; // luu a[i] vao x.
for(k=0;k<2;k++)
{
gotoxy(xi,yi++);textcolor(GREEN);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
delay(DELAY);
}
for(k=0;k<3;k++)
{
gotoxy(xi++,yi);textcolor(GREEN);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
delay(DELAY);
}
x=a[i];
a[i]=-1;
}
void chenvao(int i,int j,int d,int x)
{
int xj=cot+2+5*j;
int yi=d+3;
int xi=cot+2+i*5+3;
int k;
gotoxy(xi,yi);cprintf(" ");
while(xi>xj)
{
gotoxy(xi--,yi);textcolor(YELLOW);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",x);
delay(100);
}
for(k=0;k<2;k++)
{
gotoxy(xi,yi--);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",x);
delay(100);
}
a[j]=x;
}
void doi(int i,int j) ///////// 2 vi tri cung do cao
{
int xi=cot+2+i*5;
int yi=DONG+1;
int xj=cot+2+j*5;
int yj=DONG+1;
int xdest=xj;
int k;
textcolor(YELLOW);
for(k=0;k<2;k++)
{
gotoxy(xi,yi--);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
/////////////////////////////////
gotoxy(xj,yj++);cprintf(" ");
gotoxy(xj,yj);cprintf(" ");
delay(DELAY-40);
}
while(xi<xdest)
{
gotoxy(xi++,yi);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
////////////////////////////////
gotoxy(xj--,yj);cprintf(" ");
gotoxy(xj,yj);cprintf(" ");
delay(DELAY-40);
}
for(k=0;k<2;k++)
{
gotoxy(xi,yi++);cprintf(" ");
gotoxy(xi,yi);cprintf("%2d",a[i]);
/////////////////////////////////
gotoxy(xj,yj--);cprintf(" ");
gotoxy(xj,yj);cprintf(" ");
delay(DELAY-40);
}
xdest=a[i];
a[i]=a[j];
a[j]=xdest;
}

void insertionsort()
{
char cl;
char tieude[]="CHUONG TRINH MO PHONG PHUONG PHAP INSERTION SORT",ten[]="LE THANH HAU",mssv[]="MSSV: 08101B0015";
int i,j,pos,x;
giaodien(tieude,DONG);
textcolor(YELLOW);
gotoxy((119-strlen(tieude))/2,3);cprintf("%s",ten);
gotoxy((115-strlen(tieude))/2,4);cprintf("%s",mssv);
textcolor(YELLOW);
gotoxy(1,DONG-4);cprintf(" ");
gotoxy(1,DONG+6);cprintf("Bien i");
//thao tac di chuyen chuot
menutanggiam(cl);
if(cl!=27){
switch(cl)
{
case'T':gotoxy(1,25);clreol();printf("Dang sap xep tang");
for(i=1;i<MAX;i++)
{
in_bien_j(i,DONG,24);
pos=i-1;
rangoaidoi(i,DONG,x);delay(200);
while(pos>=0&&a[pos]>x)
{
doi(pos,pos+1);
pos--;
}
chenvao(i,pos+1,DONG,x);

}
break;
case'G':gotoxy(1,25);clreol();printf("Dang sap xep giam");
for(i=1;i<MAX;i++)
{
in_bien_j(i,DONG,24);
pos=i-1;
rangoaidoi(i,DONG,x);delay(200);
while(pos>=0&&a[pos]<x)
{
doi(pos,pos+1);
pos--;
}
chenvao(i,pos+1,DONG,x);
}
break;
}
xoa_bien_j(MAX-1,DONG);/////xoa bien j cuoi cung
gotoxy(30,18);clreol();textcolor(YELLOW);cprintf("SAP XEP HOAN THANH");
gotoxy(1,25);clreol();gotoxy(25,25);textcolor(WHITE);cprintf("PRESS ESC TO EXIT,ANYKEY TO CONTINUE");
}gotoxy(25,25);textcolor(WHITE);cprintf("PRESS ESC TO EXIT,ANYKEY TO CONTINUE");
}

void main()
{
char tt;
do{
textmode(C80);
textattr(14);
clrscr();
insertionsort();
fflush(stdin);
tt=getch();
}while(tt!=27);
}
Về Đầu Trang Go down
https://n3ctim.forumvi.net
 
Phương pháp chèn trực tiếp (đồ họa)
Về Đầu Trang 
Trang 1 trong tổng số 1 trang
 Similar topics
-
» Những phương pháp hạn chế bị hack account
» Cấu trúc sinh viên

Permissions in this forum:Bạn không có quyền trả lời bài viết
NHÓM 3 CTIM :: Học hành :: Bài tập-
Chuyển đến