1. Trang chủ
  2. » Công Nghệ Thông Tin

Quản lý thư viện bằng C++

49 4,6K 13

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 49
Dung lượng 38,59 KB

Nội dung

Quản lý thư viện bằng mảng, cây nhị phân, danh sách liệt kê

Bài Tập Quản Thư Viện Bằng Mãng : #include<stdio.h> #include<conio.h> #include<string.h> #include<iostream> struct thuvien { char ms[10],ts[20],theloai[20],tacgia[20],nxb[20]; int sl; }; thuvien tv[100]; int n; void nhap() { system("cls"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t | MOI BAN NHAP TONG SO SACH BAN CAN NHAP VAO THU VIEN |\n"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t\t>>=======>\t NHAP:\t"); scanf("%d",&n); for(int i=0;i<n;++i) { printf("\t\t>>=======>\tDAY LA QUYEN THU\t>>=======>>: %d\n",i+1); fflush(stdin); printf("\n Nhap Ma Sach :\t"); gets(tv[i].ms); printf("\n Nhap Ten Sach :\t"); gets(tv[i].ts); printf("\n Nhap The Loai :\t"); gets(tv[i].theloai); printf("\n NHap Tac Gia :\t"); gets(tv[i].tacgia); printf("\n Nhap Nha Xuat ban:\t"); gets(tv[i].nxb); printf("\n Nhap So Luong :\t"); scanf("%d",&tv[i].sl); } printf("\t\t <------------------------------------------------------>\n"); printf("\t\t <--------------NHAN ENTER DE VAO LAI MENU-------------- >\n"); printf("\t\t <------------------------------------------------------>\n"); getch(); } void xuat() { system("cls"); int NguyenCungChanh=0; for (int i=0;i<n;++i) { printf("\n\t\t\t\tQUYEN THU >>======> \t%d",++NguyenCungChanh); printf("\n\t\t########################################################"); printf("\n\t\t| Ma Sach | \t%s ",tv[i].ms); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Ten Sach | \t%s ",tv[i].ts); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| The Loai | \t%s ",tv[i].theloai); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Tac Gia | \t%s ",tv[i].tacgia); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| NXB | \t%s ",tv[i].nxb); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| So Luong | \t%d ",tv[i].sl); printf("\n\t\t########################################################"); } printf("\t\t\t <------------------------------------------------------>\n"); printf("\t\t <--------------NHAN ENTER DE VAO LAI MENU-------------- >\n"); printf("\t\t <------------------------------------------------------>\n"); getch(); } void timkiem() { system("cls"); char ms[10]; printf("\n\t\t <-MOI BAN NHAP MA SACH DE BAN TIM THAY SACH BAN MUON->:"); fflush(stdin); gets(ms); int k=0; int i; for (i=0;i<n;++i) if(strcmp(ms,tv[i].ms)==0) { printf("\n\t\t\t\tQUYEN THU >>======> \t%d",++k); printf("\n\t\t########################################################"); printf("\n\t\t| Ma Sach | \t%s ",tv[i].ms); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Ten Sach | \t%s ",tv[i].ts); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| The Loai | \t%s ",tv[i].theloai); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Tac Gia | \t%s ",tv[i].tacgia); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| NXB | \t%s ",tv[i].nxb); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| So Luong | \t%d ",tv[i].sl); printf("\n\t\t########################################################"); printf("\t\t\t <----DAY LA THONG TIN MA SACH DAU TIEN MA BAN NHAP ---->\n"); break; } if(i==n) printf("\n\t\t <---------KHONG TIM THAY MA SACH BAN CAN TIM----------->\n"); printf("\t\t <------------------------------------------------------>\n"); printf("\t\t <--------------NHAN ENTER DE VAO LAI MENU-------------- >\n"); printf("\t\t <------------------------------------------------------>\n"); getch(); } void xoa() { system("cls"); printf("\t >>====> MOI BAN NHAP MA SACH BAN CAN XOA >>===>\t"); char ms[10]; fflush(stdin); gets(ms); for(int i=0;i<n;++i) if(strcmp(ms,tv[i].ms)==0) { for(int j=i;j<n-1;++j) tv[j]=tv[j+1]; --n; break; } xuat(); } void tang() { system("cls"); printf("\t\t <------------------------------------------------------>\n"); printf("\t\t <--------SAP XEP SO LUONG SACH TU CAO XUONG THAP------->\n"); printf("\t\t <------------------------------------------------------>\n"); for (int i=0;i<n-1;++i) { int m=i; for(int j=i+1;j<n;++j) if(tv[m].sl<tv[j].sl) m=j; thuvien t=tv[i]; tv[i]=tv[m]; tv[m]=t; } xuat(); } void giam() { system("cls"); for (int i=1;i<n;++i) { int x=tv[i].sl; for(int j=i-1;j>=0;--j) if(x<tv[j].sl) tv[j+1].sl=tv[j].sl; else break; tv[j+1].sl=x; } xuat(); } void sapxep() { system("cls"); while (1) { printf("\t\t\t>>=======> >>=====>\t<=====<< <=======<<\n"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t --CHAO MUNG BAN DEN VOI THANH CONG CU SAP XEP DON GIAN--\n"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t -------CO 2 THANH CONG CU SAP XEP (TANG) VA (GIAM)------\n"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t ----------------NHAP Z .DE CHON TANG DAN----------------\n"); printf("\t\t ----------------NHAP Y .DE CHON GIAM DAN----------------\n"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t THANH CONG CU NAY SAP XEP THEO SO LUONG SACH MA BAN NHAP\n"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t -------NHAP X . DE THOAT KHOI THANH CONG CU SAP XEP-----\n"); printf("\t\t --------------------------------------------------------\n"); printf("\t\t\t MOI BAN NHAP (Z) HOAC (Y) DE XEM HIEU QUA\t"); char NguyenCungChanh; scanf("%s",&NguyenCungChanh); if (NguyenCungChanh=='x') break; else if(NguyenCungChanh=='z') tang(); else if(NguyenCungChanh=='y') giam(); } } void lietke() { system("cls"); char ms[10]; printf("\n\t\t <----- MOI BAN NHAP MA SACH BAN CAN LIET KE RA ----->"); fflush(stdin); gets(ms); int NguyenCungChanh=0; int i; for (i=0;i<n;++i) if(strcmp(ms,tv[i].ms)==0) { printf("\n\t\t\t\tQUYEN THU >>======> \t%d",++NguyenCungChanh); printf("\n\t\t########################################################"); printf("\n\t\t| Ma Sach | \t%s ",tv[i].ms); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Ten Sach | \t%s ",tv[i].ts); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| The Loai | \t%s ",tv[i].theloai); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Tac Gia | \t%s ",tv[i].tacgia); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| NXB | \t%s ",tv[i].nxb); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| So Luong | \t%d ",tv[i].sl); printf("\n\t\t########################################################"); } printf("\t\t\t\t>>=======> >>=====>\t<=====<< <=======<<\n"); printf("\t\t <------------------------------------------------------>\n"); printf("\t\t < MINH DA LIET KE TAT CA THONG TIN SACH CO CUNG MA SACH>\n"); printf("\t\t <------------------------------------------------------>\n"); printf("\t\t <------------------------------------------------------>\n"); printf("\t\t <--------------NHAN ENTER DE VAO LAI MENU-------------- >\n"); printf("\t\t <------------------------------------------------------>\n"); getch(); } void lonhon() { system("cls"); int CungChanh=0; int SoCanNhapVao; printf(">>===> >>===> NHAP SO LUONG SACH DE LIET KE SO LUONG SACH > HON :\t"); scanf("%d",&SoCanNhapVao); for (int NguyenCungChanh=0; NguyenCungChanh<n;NguyenCungChanh+ +) if(tv[NguyenCungChanh].sl > SoCanNhapVao) { printf("\n\t\t\t\tQUYEN THU >>======> \t%d",++CungChanh); printf("\n\t\t########################################################"); printf("\n\t\t| Ma Sach | \t%s ",tv[NguyenCungChanh].ms); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Ten Sach | \t%s ",tv[NguyenCungChanh].ts); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| The Loai | \t%s ",tv[NguyenCungChanh].theloai); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Tac Gia | \t%s ",tv[NguyenCungChanh].tacgia); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| NXB | \t%s ",tv[NguyenCungChanh].nxb); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| So Luong | \t%d ",tv[NguyenCungChanh].sl); printf("\n\t\t########################################################"); } printf("\t\t\t <------------------------------------------------------>\n"); printf("\t\t <--------------NHAN ENTER DE VAO LAI MENU-------------- >\n"); printf("\t\t <------------------------------------------------------>\n"); getch(); } void nhohon() { system("cls"); int SoCanNhapVao; int CungChanh=0; printf(">>====> >>===> NHAP SO LUONG SACH DE LIET KE SO LUONG SACH < HON :\t"); scanf("%d",&SoCanNhapVao); for (int NguyenCungChanh=0; NguyenCungChanh<n;NguyenCungChanh+ +) if(tv[NguyenCungChanh].sl < SoCanNhapVao) { printf("\n\t\t\t\tQUYEN THU >>======> \t%d",++CungChanh); printf("\n\t\t########################################################"); printf("\n\t\t| Ma Sach | \t%s ",tv[NguyenCungChanh].ms); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Ten Sach | \t%s ",tv[NguyenCungChanh].ts); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| The Loai | \t%s ",tv[NguyenCungChanh].theloai); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| Tac Gia | \t%s ",tv[NguyenCungChanh].tacgia); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| NXB | \t%s ",tv[NguyenCungChanh].nxb); printf("\n\t\t#-----------#------------------------------------------#"); printf("\n\t\t| So Luong | \t%d ",tv[NguyenCungChanh].sl); printf("\n\t\t########################################################"); } printf("\t\t\t <------------------------------------------------------>\n"); printf("\t\t <--------------NHAN ENTER DE VAO LAI MENU-------------- >\n"); printf("\t\t <------------------------------------------------------>\n"); getch(); } int tong1() { int s=0; int sl; for(int i=0;i<n;++i) s=s+tv[i].sl; return s; } void tong() { system("cls"); while(1) { printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++\n"); printf("\t\t + BAN C0 CHAC RANG BAN MU0N XEM T0NG S0 LU0NG SACH +\n"); printf("\t\t + HIEN THU VIEN DANG CHUA KH0NG ???? +\n"); printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++\n"); printf("\t\t + Y(YES).MU0N XEM S0 LU0NG SACH +\n"); printf("\t\t + N(N0).KH0NG MU0N XEM NUA +\n"); printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++\n"); printf("\t\t\t M0I BAN NHAP Y <==<<0R>>==> N :\t"); char v; scanf("%s",&v); if (v=='n') break; else if (v=='y') system("cls"); int s; printf("\n\n\n"); printf("\t>>====> Tong So Sach Dang Chua Trong Thu Vien La : %d\t Quyen Sach\n", tong1()); printf("\n\n\n"); printf("\t\t <------------------------------------------------------>\n"); printf("\t\t <--------------NHAN ENTER DE VAO LAI MENU-------------- >\n"); printf("\t\t <------------------------------------------------------>\n"); getch(); } } void kieulk() { system("cls"); while(1) { printf("\t\t\t>>=======> >>=====>\t<=====<< <=======<<\n"); printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++\n"); printf("\t\t + MENU LIET KE +\n"); printf("\t\t + 1. LIET KE THEO MA SACH +\n"); [...]... (NguyenCungChanh=='y') menu(); else if(NguyenCungChanh=='n') break; } } void caidat() { system("cls"); while (1) { printf("\t\t \n"); printf("\t\t |CHAO MUNG BAN DEN VOI UNG DUNG QUAN LY THU VIEN BANG C++| \n"); printf("\t\t | |\n"); printf("\t\t | |\n"); printf("\t\t | CO 2 CACH DE BAN VAO MENU CHINH |\n"); printf("\t\t | ... caidatcham() { system("cls"); while(1) { printf("\t\t\t>>=======> >>=====>\t >\n"); printf("\t\t >- KHONG MUON NHAP NUA THU NHAN ENTER NHE ->\n"); printf("\t\t > >\n"); printf("\t\t NHAP THONG THIN PHONG THU NHAT %d\n", + +i); printf("\n Nhap Ma Phong :\t"); gets(mp); if (strcmp (mp, "\0") == 0) break; if (head == NULL) { head = new karaook; tail = head;... (HocCHoCoAiCungDuocThi==5) sua(); else if (HocCHoCoAiCungDuocThi==6) tong(); else if (HocCHoCoAiCungDuocThi==0) print(); } } // menu nhap xuat void menu() { system("cls"); while (1) { printf("\t\t >============> QUAN LY KARAO0K 0.G0 B0 MENU TUNG BU0C 1.NHAP \n"); printf("\t\t CAM ON BAN DA CHON QUAN LY KARAO0K CUA TOI \n"); printf("\t\t > >\n"); printf("\t\t MOI BAN CHON CACH CAI DAT CHUONG TRINH \n"); printf("\t\t\n"); printf("\t\t CACH 1 NHAN PHIM 1 CAI DAT NHANH \n"); printf("\t\t... (karaook *p=head;p !=NULL; p=p->next) s=s+p->tt; return s; } //menu tinh tong void tong() { system("cls"); while (1) { printf("\t\t > ->\n"); printf("\t\t >=BAN C0 XEM T0NG TIEN D0ANH THU DAU VA0 K0=>\n"); printf("\t\t > ->\n"); printf("\t\t >= Y (YES).MU0N XEM GAP =>\n"); printf("\t\t >= N (N0).TH0I K0 XEM XEM SAU =>\n"); printf("\t\t > ->\n");... >\n"); getch(); } // Ham Xuat Nay Minh Da lam Tieu De cho no nen Viet Print Hoi Nhieu void print() { system("cls"); int i=0; karaook *p = head; while (p!=NULL) { printf("\n\t\t\t\tKHACH HANG THU >>===>\t%d",++i); printf("\n\t\t####################################################"); printf("\n\t\tMa Phong :\t"); printf("%s",p->mp); printf("\n\t\t# #"); printf("\n\t\tMa... int x; int i=0; printf(">>===>NHAP SO TIEN DE LIET KE CHI TIET KHACH HANG CO SO TIEN > HON:"); scanf("%d",&x); for (karaook *p=head;p != NULL;p = p->next ) if ( p->tt >x ) { printf("\n\t\t\t\tKHACH HANG THU >>===>\t%d",++i); printf("\n\t\t>>>>>>>>>>>>>>>>>>>>>>>>>> . -------------------------------------------------------- "); printf(" |CHAO MUNG BAN DEN VOI UNG DUNG QUAN LY THU VIEN BANG C++| "); printf(" |--------------------------------------------------------| ");. printf(" +++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++ "); printf(" +------------------- -QUAN LY THU VIEN- ------------------ + "); printf(" +-------CHON Y.(YES)

Ngày đăng: 04/01/2014, 21:36

TỪ KHÓA LIÊN QUAN

w