Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 16 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
16
Dung lượng
17,59 KB
Nội dung
#include #include #include #define MAXQUEUE 100 #define TRUE #define FALSE //khai bao cau truc khach hang typedef struct khachhang{ char hoten[50]; int sdt; char diachi[100]; int masp; char tensanpham[50]; }kh; //khai bao cau truc ve san pham typedef struct sanpham{ int Masp; char Tensanpham[50]; int soluong; int gia; }sp; //khai bao hang doi luu thong tin dat ve struct QueueA { int headA, tailA; kh data[MAXQUEUE]; }; //khai bao hang doi luu thong tin ve de ban struct QueueB { int headB,tailB; sp data[MAXQUEUE]; }; //khoi tao hang doi void khoitao(struct QueueA *a) { a->headA=a->tailA=NULL; } //kiem tra hang doi rong - chua co don dat hang int empty(struct QueueA *a) { if(a->headA==a->tailA) return TRUE; else return FALSE; } //them mot don hang void insert(struct QueueA *a, kh x) { if(a->tailA == MAXQUEUE-1) a->tailA = 0; else (a->tailA)++; if(a->headA==a->tailA) printf("\n don dat ve toi da khong the them"); else a->data[a->tailA] = x; } //xuat mot don hang kh remove(struct QueueA *a) { if(empty(a)) printf("\nkhong co don dat hang"); else { if(a->headA == MAXQUEUE-1) a->headA=0; else (a->headA)++; return(a->data[a->headA]); } } //duyet don hang void indonhang(struct QueueA *a) { int i; if(empty(a)) { printf("\nkhong co don hang"); return; } if(a->tailA == MAXQUEUE-1) i = 0; else i = a->tailA+1; while(i!=a->tailA) { printf("\nKhach hang co ten:%s co so dien thoai:%d va co dia chi:%s dat san pham co ma san pham:%d ten san pham:%s ", a->data[i].hoten, a>data[i].sdt,a->data[i].diachi,a->data[i].masp,a->data[i].tensanpham); if(i == MAXQUEUE-1) i = 0; else i++; } printf("\nKhach hang co ten:%s co so dien thoai:%d va co dia chi:%s dat san pham co ma san pham:%d ten san pham:%s ", a->data[i].hoten, a>data[i].sdt,a->data[i].diachi,a->data[i].masp,a->data[i].tensanpham);//nut cuoi } //Cac thao tac tren hang doi luu thong tin ve de ban// //khoi tao hang doi void khoitao(struct QueueB *b) { b->headB=b->tailB=NULL; } //Kiem tra hang doi rong - khong co ve de ban int empty(struct QueueB *b) { if(b->headB==b->tailB) return TRUE; else return FALSE; } //Them mot sp de ban void insert(struct QueueB *b, sp y) { if(b->tailB == MAXQUEUE-1) b->tailB = 0; else (b->tailB)++; if(b->headB==b->tailB) printf("\nsp de ban toi da khong the them"); else b->data[b->tailB] = y; } //In danh sach san pham de ban void inve(struct QueueB *b) { int i; if(empty(b)) { printf("\nkhong co sp de ban"); return; } if(b->tailB == MAXQUEUE-1) i = 0; else i = b->tailB+1; while(i!=b->tailB) { printf("\nSan pham co ma:%d Ten san pham:%s So luong:%d voi gia: %d",b->data[i].Masp, b->data[i].Tensanpham, ,b->data[i].soluong,b->data[i].gia); if(i == MAXQUEUE-1) i = 0; else i++; } printf("\nSan pham co ma:%d Ten san pham:%s So luong:%d voi gia: %d",b->data[i].Masp, b->data[i].Tensanpham, ,b->data[i].soluong,b>data[i].gia);//nut cuoi } //Xuat mot san pham de ban cho khach vt remove(struct QueueB *b) { if(empty(b)) printf("\nkhong co don dat hang"); else { if(b->headB == MAXQUEUE-1) b->headB=0; else (b->headB)++; return(b->data[b->headB]); } } //co che khop lenh giua hai hang doi// void bansp(struct QueueA *a, struct QueueB *b) { remove(b); remove(a); if(a->data[a->headA].masp!=b->data[b->headB].Masp && a->data[a>headA].tensanpham!=b->data[b->headB].Tensanpham) { printf("\nkhach hang chua mua duoc sp"); } else printf("\nkhach hang da mua duoc sp"); } int main() { struct QueueA a; struct QueueB b; int chucnang, head1, head2; char c; khachhang kh; sanpham sp; khoitao(&a); khoitao(&b); { printf("\n Cac chuc nang cua chuong trinh:"); printf("\n1: Nhap mot don hang"); printf("\n2: In danh sach cac don hang"); printf("\n3: Xem don hang chuan bi xuat"); printf("\n4: Xem don hang moi nhap"); printf("\n5: Xuat mot don hang"); printf("\n6: Nhap sp de ban"); printf("\n7: In danh sach sp de ban"); printf("\n8: Xem sp chuan bi ban cho khach"); printf("\n9: Xuat sp ban cho khach hang"); printf("\n10: Khach hang mua sp"); printf("\n0: Ket thuc chuong trinh"); printf("\nChuc nang ban chon:"); scanf("%d",&chucnang); switch(chucnang) { case 1: { printf("\nTen khach hang:"); fflush(stdin); scanf("%s",&kh.hoten); printf("\nSo dien thoai khach hang:"); scanf("%d",&kh.sdt); printf("\nDia chi:"); fflush(stdin); scanf("%d",&kh.diachi); printf("\nMa san pham:"); scanf("%d",&kh.masp); printf("\nTen san pham:"); fflush(stdin); scanf("%d",&kh.tensanpham); insert(&a,kh); break; } case 2: { printf("\Danh sach don hang:"); printf("\n Ten kh:%s So dien thoai:%d dia chi:%s ma sp: %d Ten san pham:%s"); indonhang(&a); break; } case 3: { if(a.headA == MAXQUEUE-1) a.headA=a.headA+1; printf("\nDon hang chuan bi xuat: Tenkh:%s Sodt:%d Dia chi:%s Ma sp:%d Ten sp:%s" ,kh.hoten,kh.sdt,kh.diachi,kh.masp,kh.tensanpham); break; } case 4: { printf("\nDon hang chuan bi xuat: Tenkh:%s Sodt:%d Dia chi:%s Ma sp:%d Ten sp:%s" ,kh.hoten,kh.sdt,kh.diachi,kh.masp,kh.tensanpham); break; } case 5: { if(!empty(&a)) { kh = remove(&a); printf("\nDon hang xuat:Ten:%s ",kh.hoten); } else printf("\nChua co don dat hang"); break; } case 6: { printf("\nMa sp:"); scanf("%d",&sp.Masp); printf("\nTen san pham:"); scanf("%s",&sp.Tensanpham); printf("\nso luong:"); scanf("%d",&sp.soluong); printf("\nGia sp:"); scanf("%d",&sp.gia); insert(&b,sp); break; } case 7: { printf("\nDanh sach sp de ban:"); inve(&b); break; } case 8: { if(b.headB == MAXQUEUE-1) b.headB=b.headB+1; printf("\nSan pham chuan bi ban cho khach hang: Ma sp: %d Ten sp:%s So luong:%d Gia:%d ",sp.Masp,sp.Tensanpham,sp.soluong,sp.giave); break; } case 9: { if(!empty(&b)) { vt = remove(&b); printf("\nsp ban xuat de ban cho khach hang: Ma sp:%d Ten sp:%s", sp.Masp, sp.Tensanpham); } else printf("\nKhong sp"); break; } case 10: { printf("\Ban sp"); banve(&a,&b); break; } } }while(chucnang != 0); return 0; } [...]... khach hang:"); fflush(stdin); scanf("%s",&kh.hoten); printf("\nSo dien thoai khach hang:"); scanf("%d",&kh.sdt); printf("\nDia chi:"); fflush(stdin); scanf("%d",&kh.diachi); printf("\nMa san pham:"); scanf("%d",&kh.masp); printf("\nTen san pham:"); fflush(stdin); scanf("%d",&kh.tensanpham); insert(&a,kh); break; } case 2: { printf("\Danh sach don hang:"); printf("\n Ten kh:%s So dien thoai:%d dia chi:%s... printf("\nChua co don dat hang"); break; } case 6: { printf("\nMa sp:"); scanf("%d",&sp.Masp); printf("\nTen san pham:"); scanf("%s",&sp.Tensanpham); printf("\nso luong:"); scanf("%d",&sp.soluong); printf("\nGia sp:"); scanf("%d",&sp.gia); insert(&b,sp); break; } case 7: { printf("\nDanh sach sp de ban:"); inve(&b); break; } case 8: { if(b.headB == MAXQUEUE-1) b.headB=b.headB+1; printf("\nSan pham chuan... pham:%s"); indonhang(&a); break; } case 3: { if(a.headA == MAXQUEUE-1) a.headA=a.headA+1; printf("\nDon hang chuan bi xuat: Tenkh:%s Sodt:%d Dia chi:%s Ma sp:%d Ten sp:%s" ,kh.hoten,kh.sdt,kh.diachi,kh.masp,kh.tensanpham); break; } case 4: { printf("\nDon hang chuan bi xuat: Tenkh:%s Sodt:%d Dia chi:%s Ma sp:%d Ten sp:%s" ,kh.hoten,kh.sdt,kh.diachi,kh.masp,kh.tensanpham); break; } case 5: { if(!empty(&a)) {... printf("\nSan pham chuan bi ban cho khach hang: Ma sp: %d Ten sp:%s So luong:%d Gia:%d ",sp.Masp,sp.Tensanpham,sp.soluong,sp.giave); break; } case 9: { if(!empty(&b)) { vt = remove(&b); printf("\nsp ban xuat de ban cho khach hang: Ma sp:%d Ten sp:%s", sp.Masp, sp.Tensanpham); } else printf("\nKhong con sp"); break; } case 10: { printf("\Ban sp"); banve(&a,&b); break; } } }while(chucnang != 0); return 0; }