(123doc) - Quan-Ly-Thu-Vien-Bang-C

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Bài Tập Quản Lý 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");
printf("\t\t + 2.NHAP SO LUONG DE LIET KE SO LUONG LON
HON +\n");
printf("\t\t + 3.NHAP SO LUONG DE LIET KE SO LUONG NHO
HON +\n");
printf("\t\t + 0.THOAT MENU LIET KE +\n");
printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++
++++++++++++\n");
printf("\t\t\t>>======>\tNHAP :\t");
int NguyenCungChanh;
scanf("%d",&NguyenCungChanh);
if (NguyenCungChanh==0)
break;
else if (NguyenCungChanh==1)
lietke();
else if (NguyenCungChanh==2)
lonhon();
else if (NguyenCungChanh==3)
nhohon();
}

}
void sua()
{
system("cls");
char ms[10],ts[20],theloai[20],tacgia[20],nxb[20];
int sl;
fflush(stdin);
printf("\n Nhap Ma So Can Sua:\t");
gets(ms);
printf("\n Nhap Ten Sach Moi:\t");
gets(ts);
printf("\n Nhap The Loai Moi:\t");
gets(theloai);
printf("\n Nhap Tac Gia Moi:\t");
gets(tacgia);
printf("\n Nhap Nha Xuat Ban Moi:\t");
gets(nxb);
printf("\n Nhap So Luong Sach Moi:\t");
scanf("%d",&sl);
for(int i=0;i<n;++i)
if (strcmp(ms,tv[i].ms)==0)
{
strcpy(tv[i].ms,ms);
strcpy(tv[i].ts,ts);
strcpy(tv[i].theloai,theloai);
strcpy(tv[i].tacgia,tacgia);
strcpy(tv[i].nxb,nxb);
tv[i].sl=sl;
}
xuat();
getch();

}
void menu()
{
system("cls");
while(1)
{
printf("\t\t\t>>=======> >>=====>\t<=====<< <=======<<\n");
printf("\t\t --------------------------------------------------------\n");
printf("\t\t|| DAY LA MENU CHINH CUA MINH MOI BAN XEM
KY ||\n");
printf("\t\t||------------------------------------------------------||\n");
printf("\t\t|| 0.Thoat || || 4.Xoa ||\n");
printf("\t\t|| 1.Nhap || || 5.Sap Xep ||\n");
printf("\t\t|| 2.Xuat || || 6.Liet Ke ||\n");
printf("\t\t|| 3.Tim Kiem || || 7.Sua ||\n");
printf("\t\t|| || || 8.Tong ||\n");
printf("\t\t||------------------------------------------------------||\n");
printf("\t\t|| LUU Y : NHAP SO VAO PHAI NHAN ENTER NHE
||\n");
printf("\t\t --------------------------------------------------------\n");
printf("\t\tDU LIEU HIEN DANG CON TRONG MOI BAN NHAN 1
DE NHAP DU LIEU :");
int N;
scanf("%d",&N);
if (N==0)
break;
else if(N==1)
nhap();
else if(N==2)
xuat();
else if(N==3)
timkiem();
else if(N==4)
xoa();
else if(N==5)
sapxep();
else if(N==6)
kieulk();
else if (N==7)
sua();
else if (N==8)
tong();

}
}
void caidatcham()
{
system("cls");
while(1)
{
printf("\t\t\t>>=======> >>=====>\t<=====<< <=======<<\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
++++++++++++\n");
printf("\t\t+--------------------QUAN LY THU VIEN-------------------
+\n");
printf("\t\t+-------CHON Y.(YES) VAO MENU--------N.(N0)
THOAT-------+\n");
printf("\t\t+-------------------------------------------------------+\n");
printf("\t\t+--------------------NGUYEN CUNG CHANH------------------
+\n");
printf("\t\t+-------------------------TM05A3------------------------+\n");
printf("\t\t+------------------------12310433-----------------------+\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
++++++++++++\n");
printf("\t\t\t >>=====>\tMOI NHAP Y HOAC N :\t");
char NguyenCungChanh;
scanf("%s",&NguyenCungChanh);
if (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 |--------------------------------------------------------|\n");
printf("\t\t |-------CACH 1 : NHAN PHIM 1 DE CAI DAT NHANH VAO
MENU---|\n");
printf("\t\t |-------CACH 2 : NHAN PHIM 2 DE CAI DAT TUNG BUOC
VAO----|\n");
printf("\t\t |--------------------------------------------------------|\n");
printf("\t\t |--------------------------------------------------------|\n");
printf("\t\t |---------NHAN PHIM 0 VA ENTER 2 LAN DE THOAT
NHANH------|\n");
printf("\t\t |--------------------------------------------------------|\n");
printf("\t\t |--------------------------------------------------------|\n");
printf("\t\t |--------------------NGUYEN CUNG CHANH-------------------|\n");
printf("\t\t |--------------------------TM05A3------------------------|\n");
printf("\t\t |-------------------------12310433-----------------------|\n");
printf("\t\t |--------------------------------------------------------|\n");
printf("\t\t |--------------------------------------------------------|\n");
printf("\t\t |-----------DOC KY HUONG DAN TRUOC KHI SU
DUNG-----------|\n");
printf("\t\t |--------------------------------------------------------|\n");
printf("\t\t --------------------------------------------------------\n");
printf("\t\t MOI BAN NHAP SO DE CAI DAT HOAC THOAT CHUONG
TRINH :");
int t;
scanf("%d",&t);
if (t==0)
break;
else if(t==1)
menu();
else if(t==2)
caidatcham();

}
void main()
{
system("cls");
caidatcham();
getch();

}
Bài 2 Quản Lý karaook bằng Danh Sách Liệt Kê

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream>
struct karaook
{
char mp[10], makh[10],tenkhach[30];
int v, r, tt;
struct karaook *next;
};
karaook *head;
// Ham Nay Minh Cung Cho Cau lenh Bao minh biet phai nhap gi vao >>>>
void nhap()
{
system("cls");
int i = 0;
head = NULL;
karaook *tail;
char mp[10];
while (1)
{
fflush(stdin);
printf("\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;
}
else
{
tail->next = new karaook;
tail = tail->next;
}
char makh[10], tenkhach[30];
int v, r, tt;
printf("\n Nhap Ma Khach :\t");
gets (makh);
printf("\n Nhap Ten Khach Hang :\t");
gets(tenkhach);
printf("\n Nhap Gio Vao :\t");
scanf("%d", &v);
printf("\n Nhap Gio Ra :\t");
scanf("%d",&r);
printf("\n Nhap Tong Tien Khach Tra :\t");
scanf("%d",&tt);

strcpy (tail->mp, mp);


strcpy (tail->makh, makh);
strcpy (tail->tenkhach, tenkhach);
tail->v = v;
tail->r = r;
tail->tt = tt;

tail->next = NULL;
}
printf("\n\t\t >-------------------------------------------->\n");
printf("\t\t>- NHAN ENTER DE VAO LAI MENU BAN VUA VAO
->\n");
printf("\t\t >-------------------------------------------->\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 Khach Hang :\t");
printf("%s",p->makh);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\tTen Khach Hang :\t");
printf("%s",p->tenkhach);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\tGio Vao :\t");
printf("%d",p->v);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\tGio Ra :\t");
printf("%d",p->r);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\tTong Tien :\t");
printf("%d",p->tt);

printf("\n\t\t####################################################");
p = p->next ;
}
printf("\n\t\t >-------------------------------------------->\n");
printf("\t\t>- NHAN ENTER DE VAO LAI MENU BAN VUA VAO
->\n");
printf("\t\t >-------------------------------------------->\n");
getch();
}
void gan (karaook *p, karaook *q)
{
strcpy (p->mp, q->mp);
strcpy (p->makh, q->makh);
strcpy (p->tenkhach, q->tenkhach);
p->v = q->v;
p->r = q->r;
p->tt = q->tt;
}
void tang()
{
for (karaook *p = head; p->next != NULL; p = p->next)
{
karaook *m = p;
for (karaook *q = p->next ; q != NULL; q= q->next )
if (m->tt < q->tt)
m = q;
karaook *t = new karaook;
gan (t, m);
gan (m, p);
gan (p, t);
}
print();
getch();
}
void wap (karaook *p, karaook *q)
{
strcpy (p->mp, q->mp);
strcpy (p->makh, q->makh);
strcpy (p->tenkhach, q->tenkhach);
p->v = q->v;
p->r = q->r;
p->tt = q->tt;
}

void giam()
{
for (karaook *p = head; p->next != NULL; p = p->next)
{
karaook *m = p;
for (karaook *q = p->next ; q != NULL; q= q->next )
if (m->tt > q->tt)
m = q;
karaook *t = new karaook;
wap (t, m);
wap (m, p);
wap (p, t);
}
print();
getch();
}
//######################################################################
#################################################################
//######################################################################
#################################################################
// menu sap xep
void sapxep()
{
while(1)
{
printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++
++\n");
printf("\t\t + C0 CU SAP XEP TANG <=>GIAM +\n");
printf("\t\t + + Z.TANG DAN THE0 T0NG TIEN +\n");
printf("\t\t + + Y.GIAM DAN THE0 T0NG TIEN +\n");
printf("\t\t + + X.QUAY LAI MENU +\n");
printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++
++\n");
printf("\t\t >>====>\t M0I CHON NHAP Z H0AC Y:\t");
char HocCHoCoAiCungDuocThi;
scanf("%s",&HocCHoCoAiCungDuocThi);
if (HocCHoCoAiCungDuocThi=='z')
tang();
else if (HocCHoCoAiCungDuocThi=='y')
giam();
else if (HocCHoCoAiCungDuocThi='x')
break;
}

}
void lonhon()
{
system("cls");
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("\n\t\tMa Phong :\t");
printf("%s",p->mp);
printf("\n\t\t|--------------------------------------------------|");
printf("\n\t\t\tMa Khach Hang :\t");
printf("%s",p->makh);
printf("\n\t\t|--------------------------------------------------|");
printf("\n\t\tTen Khach Hang :\t");
printf("%s",p->tenkhach);
printf("\n\t\t|--------------------------------------------------|");
printf("\n\t\tGio Vao :\t");
printf("%d",p->v);
printf("\n\t\t|--------------------------------------------------|");
printf("\n\t\tGio Ra :\t");
printf("%d",p->r);
printf("\n\t\t|--------------------------------------------------|");
printf("\n\t\tTong Tien :\t");
printf("%d",p->tt);

printf("\n\t\t>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<");
}
printf("\n\t\t >-------------------------------------------->\n");
printf("\t\t>- NHAN ENTER DE VAO LAI MENU BAN VUA VAO
->\n");
printf("\t\t >-------------------------------------------->\n");
getch();
}
void nhohon()
{
system("cls");
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("\n\t\tMa Phong :\t");
printf("%s",p->mp);
printf("\n\t\t#---------------------------------------------------#");
printf("\n\t\tMa Khach Hang :\t");
printf("%s",p->makh);
printf("\n\t\t#---------------------------------------------------#");
printf("\n\t\tTen Khach Hang :\t");
printf("%s",p->tenkhach);
printf("\n\t\t#---------------------------------------------------#");
printf("\n\t\tGio Vao :\t");
printf("%d",p->v);
printf("\n\t\t#---------------------------------------------------#");
printf("\n\t\tGio Ra :\t");
printf("%d",p->r);
printf("\n\t\t#---------------------------------------------------#");
printf("\n\t\tTong Tien :\t");
printf("%d",p->tt);

printf("\n\t\t#####################################################");
}
printf("\n\t\t >-------------------------------------------->\n");
printf("\t\t>- NHAN ENTER DE VAO LAI MENU BAN VUA VAO
->\n");
printf("\t\t >-------------------------------------------->\n");
getch();
}
void lietke()
{
system("cls");
while (1)
{
printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t + MENU LIET KE +\n");
printf("\t\t + 1.LIET KE KHACH CO TONG TIEN > HON +\n");
printf("\t\t + 2.LIET KE KHACH CO TONG TIEN < HON +\n");
printf("\t\t + 0.TH0AT KH0I MENU LIET KE +\n");
printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++++\n");
printf("\t\t >>====> \tNHAP SO :\t");
int k;
scanf("%d",&k);
if(k==0)
break;
else if(k==1)
lonhon();
else if(k==2)
nhohon();
}

}
void them()
{
system("cls");
printf("\t\tNHAP TH0NG TIN THE0 G0I Y DE CH0 VA0 DANH SACH
\n");
printf("\t\t-----------------------------------------------\n");
char mp[10], makh[10],tenkhach[30];
int v, r, tt;
fflush(stdin);
printf("\nNhap Ma Phong Can Them :\t");
gets (mp);
printf("\nNhap Ma Khach Hang Can Them :\t");
gets (makh);
printf("\nNhap Ma Ten Khach Hang Can Them :\t");
gets (tenkhach);
printf("\nNhap Gio Va0 Cua Khach Hang Can Them :\t");
scanf("%d", &v);
printf("\nNhap Gio Ra Cua Khach Hang Can Them :\t");
scanf("%d", &r);
printf("\nNhap Tong Tien Cua Khach Hang Can Them :\t");
scanf("%d", &tt);

karaook *p = new karaook;


strcpy (p->mp, mp);
strcpy (p->makh, makh);
strcpy (p->tenkhach, tenkhach);

p->v = v;
p->r = r;
p->tt =tt;

karaook *q = head;
while (q->next != NULL)
q = q->next ;
q->next = p;
p->next = NULL;
print();
getch();
}
void xoa()
{
system("cls");
printf("\t\t >=========>>==========>>=========>>=========>>\n");
printf("\t\t >=====>>NHAP MA PHONG BAN CAN XOA<<=======<");
char mp[10];
fflush (stdin);
gets (mp);
karaook *p, *q;
if (strcmp (head->mp , mp) == 0)
{
p = head;
head = head->next;
delete p;
}
else
{
p = head;
while (p != NULL)
{
if (strcmp (p->mp, mp ) == 0)
break;
q = p;
p = p->next;
}
if (p!= NULL)
{
q->next = p->next;
delete p;
}
}
print();
getch();
}
void suane()
{
system("cls");
fflush(stdin);
char mp[10], makh[10],tenkhach[30];
int v, r, tt;
printf("\nNhap Ma Phong Can sua :\t");
gets (mp);
printf("\nNhap Ma Khach Hang Can sua :\t");
gets (makh);
printf("\nNhap Ma Ten Khach Hang Can sua :\t");
gets (tenkhach);
printf("\nNhap Gio Va0 Cua Khach Hang Can sua :\t");
scanf("%d", &v);
printf("\nNhap Gio Ra Cua Khach Hang Can sua :\t");
scanf("%d", &r);
printf("\nNhap Tong Tien Cua Khach Hang Can sua :\t");
scanf("%d", &tt);
for (karaook *p=head;p != NULL;p=p->next)
if (strcmp(mp,p->mp)==0)
{
strcpy (p->mp, mp);
strcpy (p->makh, makh);
strcpy (p->tenkhach, tenkhach);

p->v = v;
p->r = r;
p->tt =tt;
}
print();
getch();

}
void sua()
{
system("cls");
while (1)
{
printf("\t\t >-------------------------------------------->\n");
printf("\t\t >=BAN C0 MUA SUA TH0NG TIN KHACH HANG LAI
K0=>\n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t >= Y (YES).T0I MU0N SUA TH0NG TIN LAI =>\n");
printf("\t\t >= N (N0).KH0NG SUA TH0NG TIN NUA =>\n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t -------> M0I NHAP Y <---0R---> N :\t");
char HocCHoCoAiCungDuocThi;
scanf("%s",&HocCHoCoAiCungDuocThi);
if (HocCHoCoAiCungDuocThi=='y')
suane();
else if (HocCHoCoAiCungDuocThi=='n')
break;
}

}
//ham tinh tong don gian
int tt;
int tienvao()
{
int s=0;
for (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");
printf("\t\t -------> M0I NHAP Y <---0R---> N :\t");
char HocCHoCoAiCungDuocThi;
scanf("%s",&HocCHoCoAiCungDuocThi);
if (HocCHoCoAiCungDuocThi=='n')
break;
else if (HocCHoCoAiCungDuocThi=='y')
system("cls");
int s;
int tt;
printf("\n\n\n\n\n\n");
printf("\t\t-------> T0NG TIEN D0ANH THU DAU VAO LA :\t
%d",tienvao());
printf("\n\n\n\n");
printf("\n\t\t >-------------------------------------------->\n");
printf("\t\t>- NHAN ENTER DE VAO LAI MENU BAN VUA VAO
->\n");
printf("\t\t >-------------------------------------------->\n");
getch();
}
}
// menu xu ly
void congcu()
{
system("cls");
while (1)
{
printf("\t\t >-------------------------------------------->\n");
printf("\t\t >= CONG CU XU LY =>\n");
printf("\t\t >------------------------------------------->\n");
printf("\t\t >= 0.XUAT =>\n");
printf("\t\t >= 1.SAP XEP >>===========>> 2.LIET KE =>\n");
printf("\t\t >= 3.THEM >>================>> 4 .XOA =>\n");
printf("\t\t >= 5.SUA>>====================>> 6.T0NG
=>\n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t >= NHAN 8 DE THOAT THANH CONG CU NAY
=>\n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t\t\t\t");
int HocCHoCoAiCungDuocThi;
scanf("%d", &HocCHoCoAiCungDuocThi);
if (HocCHoCoAiCungDuocThi==8)
break;
else if (HocCHoCoAiCungDuocThi==1)
sapxep();
else if (HocCHoCoAiCungDuocThi==2)
lietke();
else if (HocCHoCoAiCungDuocThi==3)
them();
else if (HocCHoCoAiCungDuocThi==4)
xoa();
else if (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
<==============<\n");
printf("\t\t >========> 0.G0 B0 MENU TUNG BU0C
<=========<\n");
printf("\t\t >============> 1.NHAP <==============<\n");
printf("\t\t >============> <==============<\n");
printf("\t\t >NHAN PHIM 2 DE XU LU DU LIEU VUA
NHAP<\n");
printf("\t\t >=============>TM05A3<=============<\n");
printf("\t\t MOI BAN NHAP SO VAO :");
int N;
scanf("%d", &N);
if (N == 1)
nhap();
else if (N==2)
congcu();
else if (N== 0)
break;
}
}
// menu cai dat
void chaydichomau()
{
system("cls");
while (1)
{
printf("\t\t >-------------------------------------------->\n");
printf("\t\t >=MOI BAN CHON Y (YES) HOAC N(N0) DE CAI
DAT=>\n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t >= Y. THUC HIEN QUA TRINH CAI DAT VAO MENU
=>\n");
printf("\t\t >= N. QUAY LAI BUOC CHON CACH CAI DAT
=>\n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t MOI BAN NHAP Y (YES) HOAC N (NO)\t");
char HocCHoCoAiCungDuocThi;
scanf("%s",&HocCHoCoAiCungDuocThi);
if (HocCHoCoAiCungDuocThi=='y')
menu();
else if (HocCHoCoAiCungDuocThi=='n')
break;
}
}
void bksg()
{
system("cls");
while (1)
{
printf("\t\t >-------------------------------------------->\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 CACH 2 NHAN PHIM 2 DE CAI DAT TUNG BUOC
\n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t PHIM 0 VA ENTER 2 LAN DE KHONG CAI DAT
NUA \n");
printf("\t\t >-------------------------------------------->\n");
printf("\t\t MOI BAN CHON CACH CAI DAT DE VAO MENU
CHINH ");
int HocCHoCoAiCungDuocThi;
scanf("%d",&HocCHoCoAiCungDuocThi);
if (HocCHoCoAiCungDuocThi == 1)
menu();
else if (HocCHoCoAiCungDuocThi==2)
chaydichomau();
else if (HocCHoCoAiCungDuocThi==0)
break;
}
}
void main()
{
system("cls");
bksg();
getch();
}

Bài tập 3 quản lý sản phẩm bằng Cây nghị Phân >>> Phần Khó

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream>
struct sanpham
{
char ms[10], tensp[30], nb[10];
int gia, sl;
sanpham *left, *right;
};
sanpham *root;
void nhap()
{
system("cls");
sanpham *p;
root = NULL;
char ms[10], tensp[30], nb[10];
int gia, sl;
int i = 0;
while (1)
{
printf("\t\t ---------->SAN PHAM THU ------->\t %d\n\n" , ++i);
fflush(stdin);
printf("\n Nhap Ma San Pham :\t");
gets (ms);
if (strcmp (ms, "\0") == 0)
break;
if (root == NULL)
{
root = new sanpham;
root->left = NULL;
root->right = NULL;
p = root;
}
else
{
p = root;
sanpham *q;
while (p != NULL)
{
q = p;
if (strcmp (ms, p->ms) < 0)
p = p->left ;
else if (strcmp (ms, p->ms) > 0)
p = p->right ;
}
p = new sanpham;
p->left = NULL;
p->right = NULL;
if (strcmp(ms, q->ms) < 0)
q->left = p;
else
q->right = p;
}
printf("\n Nhap Ten San Pham :\t");
gets (tensp);
printf("\n Nhap Ngay Ban :\t");
gets(nb);
printf("\n Nhap Gia San Pham :\t");
scanf("%d", &gia);
printf("\n Nhap So Luong San Pham :\t");
scanf("%d", &sl);

strcpy (p->ms, ms);


strcpy (p->tensp, tensp);
strcpy (p->nb, nb);

p->gia=gia;
p->sl=sl;

}
}
void LNR (sanpham *root)
{
if (root != NULL)
{

LNR (root->left);

printf("\n\t\t####################################################");
printf("\n\t\t Ma San Pham :\t");
printf("%s",root->ms);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ten San Pham :\t");
printf("%s",root->tensp);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ngay Ban :\t");
printf("%s",root->nb);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Gia San Pham :\t");
printf("%d",root->gia);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t So Luong :\t");
printf("%d",root->sl);

printf("\n\t\t####################################################");
LNR (root->right);
}
}
void xuat()
{
system("cls");
LNR (root);
printf("\n\n");
printf("\n\t\t
>=========>>==========>>=========>>=========>>\n");
printf("\t\t>= NHAN ENTER DE VAO LAI MENU BAN VUA VAO
=>\n");
printf("\t\t >=========>>==========>>=========>>=========>>\n");
getch();
}
void NLR (sanpham *root)
{

if (root != NULL)
{

printf("\n\t\t####################################################");
printf("\n\t\t Ma San Pham :\t");
printf("%s",root->ms);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ten San Pham :\t");
printf("%s",root->tensp);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ngay Ban :\t");
printf("%s",root->nb);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Gia San Pham :\t");
printf("%d",root->gia);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t So Luong :\t");
printf("%d",root->sl);

printf("\n\t\t####################################################");
NLR (root->left);
NLR (root->right);
}
}
void xuatloai2()
{
system("cls");

NLR (root);
printf("\n\n");
printf("\t\t >>----------->DA THEM VA0 DANH SACH>>------------>\n");
printf("\n\n");
printf("\n\t\t
>=========>>==========>>=========>>=========>>\n");
printf("\t\t>= NHAN ENTER DE VAO LAI MENU BAN VUA VAO
=>\n");
printf("\t\t >=========>>==========>>=========>>=========>>\n");
getch();
}
//######################################################################
####################################################################
void them ()
{
system("cls");
char ms[10], tensp[30], nb[10];
int gia, sl;
printf("\n\t\t >>----------> M0I BAN THEM TH0NG TIN CAN THEM
>>--------->\n");
fflush(stdin);
printf("\n Nhap Ma So San Pham Can Them :\t");
gets (ms);
printf("\n Nhap Ten San Pham Can Them :\t");
gets (tensp);
printf("\n Nhap Ngay Ban Hang Can Them :\t");
gets(nb);
printf("\n Nhap Gia Cua San Pham Can Them :\t");
scanf("%d", &gia);
printf("\n Nhap So Luong San Pham Can Them :\t");
scanf("%d", &sl);

sanpham *p = root, *q;


while (p!=NULL)
{
if (strcmp (ms, p->ms) == 0)
{
printf("San Pham Nay Da Co \n");
return;
}
else if (strcmp (ms, p->ms) < 0)
{
q = p;
p = p->left ;
}
else
{
q = p;
p = p->right ;
}
}
p = new sanpham;
strcpy (p->ms, ms);
strcpy (p->tensp, tensp);
strcpy (p->nb, nb);

p->gia=gia;
p->sl=sl;

p->left = NULL;
p->right = NULL;

if (strcmp (p->ms, q->ms) < 0)


q->left = p;
else
q->right = p;

xuatloai2();
getch();

}
//############################## LIET >>>>>>> KE
######################################################################
void lk1()
{
system("cls");
printf("\t--------->NHAP MA S0 CAN LIET KE: ");
char ms[10];
fflush (stdin);
gets (ms);
sanpham *p = root;
while (p!=NULL)
{
if (strcmp (p->ms, ms) == 0)
break;
else if (strcmp (ms, p->ms) < 0)
p = p->left ;
else
p = p->right ;
}
if (p!=NULL)
{
system("cls");

printf("\n\t\t####################################################");
printf("\n\t\t Ma San Pham :\t");
printf("%s",root->ms);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ten San Pham :\t");
printf("%s",root->tensp);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ngay Ban :\t");
printf("%s",root->nb);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Gia San Pham :\t");
printf("%d",root->gia);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t So Luong :\t");
printf("%d",root->sl);
printf("\n\t\t####################################################");
printf("\n\t\t -------------> DA LIET KE S0NG <--------------");
}
else
printf("\n\t\t -------->K0 C0 SAN PHAM NAY<-------------\n");

printf("\n\t\t
>=========>>==========>>=========>>=========>>\n");
printf("\t\t>= NHAN ENTER DE VAO LAI MENU BAN VUA VAO
=>\n");
printf("\t\t >=========>>==========>>=========>>=========>>\n");
getch();

}
void NLR_sl (sanpham *root, int sl, int x)
{

if (root != NULL)
{
if (root->sl < x)
{

printf("\n\t\t####################################################");
printf("\n\t\t Ma San Pham :\t");
printf("%s",root->ms);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ten San Pham :\t");
printf("%s",root->tensp);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ngay Ban :\t");
printf("%s",root->nb);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Gia San Pham :\t");
printf("%d",root->gia);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t So Luong :\t");
printf("%d",root->sl);
printf("\n\t\t####################################################");
}
NLR_sl (root->left, sl, x );
NLR_sl (root->right, sl, x );
}
}
void lk_sl()
{
system("cls");

int sl, x ;
printf("\n\t >>======> M0I NHAP GIA TRI >>=====>:\t");
scanf("%d",&x);
NLR_sl (root, sl, x);

printf("\n\t\t
>=========>>==========>>=========>>=========>>\n");
printf("\t\t>= NHAN ENTER DE VAO LAI MENU BAN VUA VAO
=>\n");
printf("\t\t >=========>>==========>>=========>>=========>>\n");
getch();
}
void NLR_sl2 (sanpham *root, int sl, int x)
{

if (root != NULL)
{
if (root->sl > x)
{

printf("\n\t\t####################################################");
printf("\n\t\t Ma San Pham :\t");
printf("%s",root->ms);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ten San Pham :\t");
printf("%s",root->tensp);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Ngay Ban :\t");
printf("%s",root->nb);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t Gia San Pham :\t");
printf("%d",root->gia);
printf("\n\t\t#--------------------------------------------------#");
printf("\n\t\t So Luong :\t");
printf("%d",root->sl);

printf("\n\t\t####################################################");
}
NLR_sl2 (root->left, sl, x );
NLR_sl2 (root->right, sl, x );
}
}
void lk_sl2()
{
system("cls");
int sl, x ;
printf("\n\t >>======> M0I NHAP GIA TRI >>=====>:\t");
scanf("%d",&x);
NLR_sl2 (root, sl, x);

printf("\n\t\t
>=========>>==========>>=========>>=========>>\n");
printf("\t\t>= NHAN ENTER DE VAO LAI MENU BAN VUA VAO
=>\n");
printf("\t\t >=========>>==========>>=========>>=========>>\n");
getch();
}
void lietke()
{
system("cls");
while (1)
{
printf("\t\t+++++++++++++++C0NG CU XU LY LIET KE+++++++++
+++++\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
+++++\n");
printf("\t\t++ 0.TH0AT KH0I C0NG CU ++\n");
printf("\t\t++ ++++++++++++++++++++ +++ +++++++++++++++++++
++\n");
printf("\t\t++ 1.LIET KE THE0 MA SO SAN PHAM ++\n");
printf("\t\t++ 2.LIET KE SP C0 SL < TRI BAN NHAP ++\n");
printf("\t\t++ 3.LIET KE SP C0 SL > TRI BAN NHAP ++\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
+++++\n");
printf("\t\t\t >>====> M0I NHAP S0 :\t");
int yeuem;
scanf("%d",&yeuem);
if (yeuem==1)
lk1();
else if (yeuem==2)
lk_sl();
else if (yeuem==0)
break;
else if (yeuem==3)
lk_sl2();
}
}
///############################# HAM XOA DE NGHI SUA DUM` DU`M
DU`M ##########################################
/*
int del()
{
system("cls");
int x;
printf("\n Nhap ma so can xoa :%d");
scanf("%d",&x);
sanpham *p,*q,*f;
sanpham *left, *right;
p=root;
f=NULL;
char ms[10];
gets(ms);
while (p != NULL)
{
if (strcmp(ms,p->ms)==x)
break;
else
{
f = p;
if (strcmp(ms,p->ms)>x)
p =p->left;
else
p =p->right;
}

}
if (p==NULL)
return 0;
else
{
if (p->left != NULL && p->right !=NULL)
{
q = p ->right;
f = p;
while(q->left !=NULL)
{
f = q;
q = q->left;
}
p->left = q->right;
p = q;
}
if (p->letf != NULL)
q = p->left;
else
q = p->right;
if (p == root)
root = q;
else
{
if (p = f->left)
f->left = q;
else
f->right = q;
}
delete p;
return 1;
}

}*/
void sua ()
{
system("cls");
char ms[10], tensp[30], nb[10];
int gia, sl;
printf("\n\t\t\t NHAP MS THAY CAN SUA :\t ");
fflush(stdin);
gets(ms);
sanpham *p = root, *q;
while (p!=NULL)
{
if (strcmp (ms, p->ms) == 0)
{
printf("\n\n\t\t\tM0I NHAP TH0NG TIN CAN SUA :\n");
printf("\n Nhao Ma So M0i :\t ");
gets(ms);
printf("\n Nhap Ten San Pham M0i :\t");
gets (tensp);
printf("\n Nhap Ngay Ban M0i :\t");
gets(nb);
printf("\n Nhap Gia San Pham M0i :\t");
scanf("%d", &gia);
printf("\n Nhap So Luong San Pham M0i:\t");
scanf("%d", &sl);
strcpy (p->ms, ms);
strcpy (p->tensp, tensp);
strcpy (p->nb, nb);

p->gia=gia;
p->sl=sl;

return;
}
else if (strcmp (ms, p->ms) < 0)
{
q = p;
p = p->left ;
}
else
{
q = p;
p = p->right ;
}
}
printf("\n\n\t\t\t DA SUA SONG MOI CON HAM XUAT DE XEM KQ ");
printf("\n\n");
printf("\n\t\t
>=========>>==========>>=========>>=========>>\n");
printf("\t\t>= NHAN ENTER DE VAO LAI MENU BAN VUA VAO
=>\n");
printf("\t\t >=========>>==========>>=========>>=========>>\n");
getch();

}
///################################################# C0NG CU XUA LY
**************************************************************
void congcu()
{
system("cls");
while (1)
{
printf("\t\t++++++++++++++++THANH C0NG CU XU LY++++++++
+++++++\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
+++++\n");
printf("\t\t++ 0.TH0AT KH0I C0NG CU +++ 3. THEM ++\n");
printf("\t\t++ 1. XUAT +++ 4. -SUA- ++\n");
printf("\t\t++ 2. HAM XOA SUA DUM +++ 5. LIET KE ++\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
+++++\n");
printf("\t\t++ ++++++++++++++++++++++++++ ++\n");
printf("\t\t++ NGUYEN CUNG CHANH ++\n");
printf("\t\t++ TM05A3 ++\n");
printf("\t\t++ 12310433 ++\n");
printf("\t\t++ >>=======> <=========<< ++\n");
printf("\t\t++ >>=======>I L0VE Y0U<=========<< ++\n");
printf("\t\t++ >>========> <==========<< ++\n");
printf("\t\t++ >>========> <==========<< ++\n");
printf("\t\t++ >>========>II<==========<< ++\n");
printf("\t\t++ >>=======><=========<< ++\n");
printf("\t\t++ >>=====><=======<< ++\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
+++++\n");
printf("\t\t\t >>====> M0I NHAP S0 :\t");
int yeuem;
scanf("%d",&yeuem);
if (yeuem==0)
break;
else if (yeuem==1)
xuat();
else if (yeuem==3)
them();
else if (yeuem==5)
lietke();
// else if (yeuem==2)
// del();
else if (yeuem==4)
sua();
}

}
void menu()
{
system("cls");
while(1)
{
printf("\t\t +++++++++++++++++QUAN LY SAN PHAM++++++++++
+++++\n");
printf("\t\t + 0.TH0AT +\n");
printf("\t\t + 1.NHAP +\n");
printf("\t\t + 2. VA0 THANH C0NG CU +\n");
printf("\t\t + ++++++++++++++++++++++++++ +\n");
printf("\t\t + NGUYEN CUNG CHANH +\n");
printf("\t\t + TM05A3 +\n");
printf("\t\t + 12310433 +\n");
printf("\t\t + >>=======> <=========<< +\n");
printf("\t\t + >>=======>I L0VE Y0U<=========<< +\n");
printf("\t\t + >>========> <==========<< +\n");
printf("\t\t + >>========> <==========<< +\n");
printf("\t\t + >>========>II<==========<< +\n");
printf("\t\t + >>=======><=========<< +\n");
printf("\t\t + >>=====><=======<< +\n");
printf("\t\t ++++++++++++++++++++++++++++++++++++++++++++
++++\n");
printf("\t\t\t >>====> M0I NHAP S0 :\t");
int bksg;
scanf("%d",&bksg);
if (bksg==0)
break;
else if (bksg==1)
nhap();
else if (bksg==2)
congcu();
}
}
void BKSG_YEUEM()
{
system("cls");
while (1)
{
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
++++++++\n");
printf("\t\t+BAN C0 CHAC MU0N THAM QUAN->QUAN LY SAN
PHAM KH0NG +\n");
printf("\t\t+ >>=======> <=========<< +\n");
printf("\t\t+ >>=======>I L0VE Y0U<=========<<
+\n");
printf("\t\t+ >>========> <==========<< +\n");
printf("\t\t+ >>========> <==========<< +\n");
printf("\t\t+ >>========>II<==========<< +\n");
printf("\t\t+ >>=======><=========<< +\n");
printf("\t\t+ >>=====><=======<< +\n");
printf("\t\t+M0I BAN CH0N Y(YES)DE VA0 H0AC N(N0)DE LAN
SAU VA0+\n");
printf("\t\t+++++++++++++++++++++++++++++++++++++++++++++
++++++++\n");
printf("\t\t\t >>===> M0I BAN NHAP Y H0AC N :\t");
char lamgiau;
scanf("%s",&lamgiau);
if (lamgiau=='y')
menu();
else if (lamgiau=='n')
break;

}
}
void main()
{
system("cls");
menu();
getch();

You might also like