Code Bài toán quản lí sử dụng Stack C KHAI BAO DU LIEU 2 KHAI BAO CAU TRUC DU LIEU 2 KHAI BAO DANG STACK CUA DU LIEU 2 KHOI TAO STACK RONG 3 KIEM TRA STACK RONG 3 THEM PHAN TU VAO STACK 3 NHAP 1 NV 4 NHAP DANH SACH NHAN VIEN 5 IN 1 NV 5 IN DSNV 6 TIM NV CO MA X NAO DO 6 TIM VA IN TTNV CO LUONG CAO NHAT 7 TIM VA IN TTNV CO LUONG THAP NHAT 8 TIM VA IN TTNV CO SO CON > 3 9 SAP XEP NV THEO SO LUONG TANG DAN 9 SAP XEP NV THEO SO LUONG GIAM DAN 10 XOA 1 NHAN VIEN KHOI DANH SACH 11 IN PHAN TU DUNG DAU DANH SACH 12 DEM SO NHAN VIEN CO MUC LUONG TREN 4 TRIEU 13 DOI TEN NHAN VIEN CO MA X 14 TIM NV THEO TEN 15 TIM VA IN TTNV CO BANG CAP CAO HOC 16 TIM NHAN VIEN CHUA KET HON 17 THAY DOI THONG TIN NHAN VIEN CO MA X 17 IN THONG TIN NHAN VIEN DAT KET QUA TOT 19 TIM VA IN TTNV CO HE SO LUONG CAO NHAT 20 TIM VA IN TTNV CHUA CO CON 20
Mục Lục Code Bài toán quản lí sử dụng Stack C //KHAI BAO DU LIEU //KHAI BAO CAU TRUC DU LIEU //KHAI BAO DANG STACK CUA DU LIEU .2 //KHOI TAO STACK RONG //KIEM TRA STACK RONG //THEM PHAN TU VAO STACK //NHAP NV //NHAP DANH SACH NHAN VIEN //IN NV //IN DSNV //TIM NV CO MA X NAO DO //TIM VA IN TTNV CO LUONG CAO NHAT //TIM VA IN TTNV CO LUONG THAP NHAT .8 //TIM VA IN TTNV CO SO CON > //SAP XEP NV THEO SO LUONG TANG DAN //SAP XEP NV THEO SO LUONG GIAM DAN 10 //XOA NHAN VIEN KHOI DANH SACH .11 //IN PHAN TU DUNG DAU DANH SACH .12 //DEM SO NHAN VIEN CO MUC LUONG TREN TRIEU 13 //DOI TEN NHAN VIEN CO MA X 14 //TIM NV THEO TEN 15 //TIM VA IN TTNV CO BANG CAP CAO HOC 16 //TIM NHAN VIEN CHUA KET HON 17 //THAY DOI THONG TIN NHAN VIEN CO MA X .17 //IN THONG TIN NHAN VIEN DAT KET QUA TOT 19 //TIM VA IN TTNV CO HE SO LUONG CAO NHAT 20 //TIM VA IN TTNV CHUA CO CON 20 #include #include #include #include #include //KHAI BAO DU LIEU struct NV { int MNV; char Hoten[15]; char GD[5]; int Con; char TDVH[10]; char KQ[5]; float Luong,HSL; }; //KHAI BAO CAU TRUC DU LIEU struct Node { NV infor; struct Node *next; }; //KHAI BAO DANG STACK CUA DU LIEU struct Stack { Node *top; }; //KHOI TAO STACK RONG void Initstack(Stack &s) { s.top = NULL; } //KIEM TRA STACK RONG int IsEmpty( Stack s) { if( s.top==NULL) { return 1; } else { return 0; } } //THEM PHAN TU VAO STACK void Push( Stack &s,NV x) { Node *p; p= new Node(); if(p==NULL) { printf("Khong them duoc!!");exit(1); } p->infor=x; p->next=s.top; s.top=p; } //NHAP NV void NhapNV(NV &x) { float tg,pt=0; printf("Nhap ma nhan vien: ");scanf("%d",&x.MNV); printf("Nhap ten nhan vien: ");fflush(stdin);gets(x.Hoten); printf("Tinh trang hon nhan(m/s): ");fflush(stdin);gets(x.GD); printf("So con: ");scanf("%d",&x.Con); printf("Trinh van hoa(C1,C2,C3,DH,CH): ");fflush(stdin);gets(x.TDVH); printf("Ket qua lam viec(TO,TB,KE): ");fflush(stdin);gets(x.KQ); printf("Nhap he so luong(1->9): ");scanf("%f",&x.HSL); if(strcmp(x.KQ,"TO")==0) { pt=pt+(5*(x.HSL*1350000))/100; } if(x.Con>=2) { pt=pt+(5*(x.HSL*1350000))/100; } if(strcmp(x.TDVH,"CH")==0) { pt=pt+(10*(x.HSL*1350000))/100; } tg=pt+(x.HSL*1350000); x.Luong=tg; } //NHAP DANH SACH NHAN VIEN void NhapDSNV(Stack &s) { Node *p; NV x; int n,i; printf("Nhap so nhan vien: ");scanf("%d",&n); for(i=0;inext) { InNV(p->infor); } } //TIM NV CO MA X NAO DO void TimNV(Stack s) { Node *p; int n,d=0; printf("Nhap ma nhan vien can tim: ");scanf("%d",&n); for(p=s.top;p!=NULL;p=p->next) { if(p->infor.MNV==n) { d++; } } if(d>0) { printf("Co Tim Thay!"); } else { printf("Khong Tim Thay!"); } } //TIM VA IN TTNV CO LUONG CAO NHAT void NVLUONGCAO(Stack s) { Node *p; float Max; for(p=s.top;p!=NULL;p=p->next) { Max = s.top->infor.Luong; if(Max infor.Luong) { Max=p->infor.Luong; } } for(p=s.top;p!=NULL;p=p->next) { if(Max==p->infor.Luong) { InNV(p->infor); } } } //TIM VA IN TTNV CO LUONG THAP NHAT void NVLUONGTHAP(Stack s) { Node *p; float Min; for(p=s.top;p!=NULL;p=p->next) { Min = s.top->infor.Luong; if(Min>p->infor.Luong) { Min=p->infor.Luong; } } for(p=s.top;p!=NULL;p=p->next) { if(Min==p->infor.Luong) { InNV(p->infor); } } } //TIM VA IN TTNV CO SO CON > void Con3(Stack s) { Node *p; int d=0; for(p=s.top;p!=NULL;p=p->next) { if(p->infor.Con>3) { InNV(p->infor); d++; } } if(d=0) { printf("Khong co nhan vien nao co nhieu hon con!"); } } //SAP XEP NV THEO SO LUONG TANG DAN void SXLUONGTANG(Stack &s) { printf("\n Danh sach sau sap xep tang dan la:"); NV tg; Node *p; Node *q; for(p=s.top;p!=NULL;p=p->next) { for(q=p->next;q!=NULL;q=q->next) { if(p->infor.Luong>q->infor.Luong) { tg=p->infor; p->infor=q->infor; q->infor=tg; } } } InDSNV(s); } //SAP XEP NV THEO SO LUONG GIAM DAN void SXLUONGGIAM(Stack &s) { printf("\n Danh sach sau sap xep tang dan la:"); NV tg; Node *p; Node *q; for(p=s.top;p!=NULL;p=p->next) { for(q=p->next;q!=NULL;q=q->next) { if(p->infor.Luonginfor.Luong) { tg=p->infor; p->infor=q->infor; q->infor=tg; } } } InDSNV(s); } //XOA NHAN VIEN KHOI DANH SACH NV pop(Stack &s) { NV tg; Node *p; if(IsEmpty(s)==1) { printf("Stack Rong!");exit(1); } else { p=s.top; tg=p->infor; s.top=s.top->next; delete p; } return tg; } void XoanV(Stack &s) { Node *p; int n; printf("Nhap ma NV can xoa: ");scanf("%d",&n); for(p=s.top;p!=NULL;p=p->next) { if(p->infor.MNV==n) { pop(s); } } } //IN PHAN TU DUNG DAU DANH SACH void top( Stack s) { Node *p; if(IsEmpty(s)==1) { printf("Stack Rong");exit(1); } else { p=s.top; } InNV(p->infor); } //DEM SO NHAN VIEN CO MUC LUONG TREN TRIEU void DEMTREN4TRIEU(Stack s) { int d=0; Node *p; for(p=s.top;p!=NULL;p=p->next) { if(p->infor.Luong>=4000000) { d++; } } if(d>0) { printf("So nhan vien co muc luong trieu tro len: %d",d); } else { printf("Khong co nhan vien nao co luong >= 4trieu!"); } } void DEMNVBANGDH(Stack s) { int d=0; Node *p; for(p=s.top;p!=NULL;p=p->next) { if(strcmp(p->infor.TDVH,"DH")==0) { d++; } } if(d=0) { printf("So NV co bang dai hoc la: %d",d); } else { printf("Khong co NV nao co bang dai hoc!"); } } //DOI TEN NHAN VIEN CO MA X void DOITEN(Stack &s) { int n,d=0; char st[20]; Node *p; printf("Nhap ma nhan vien can doi ten: ");scanf("%d",&n); for(p=s.top;p!=NULL;p=p->next) { if(p->infor.MNV==n) { printf("Nhap ten thay doi: ");fflush(stdin);gets(st); strcpy(p->infor.Hoten,st); d++; } } if(d=0) { printf("Ma Khong Trung Khop!"); } else { printf("Doi ten cong!"); } } //TIM NV THEO TEN void TIMTEN(Stack s) { char st[20]; Node *p; int d=0; printf("Nhap ten nhan vien can tim: ");fflush(stdin);gets(st); for(p=s.top;p!=NULL;p=p->next) { if(strcmp(p->infor.Hoten,st)==0) { d++; } } if(d=0) { printf("Khong Tim Thay!"); } else { printf("Co Tim Thay!"); } } //TIM VA IN TTNV CO BANG CAP CAO HOC void NVCAOHOC(Stack s) { Node *p; for(p=s.top;p!=NULL;p=p->next) { if(strcmp(p->infor.TDVH,"CH")==0) { InNV(p->infor); } } } //TIM NHAN VIEN CHUA KET HON void NVS(Stack s) { int d=0; Node *p; for(p=s.top;p!=NULL;p=p->next) { if(strcmp(p->infor.GD,"s")==0) { InNV(p->infor); d++; } } if(d=0) { printf("Khong co NV nao da ket hon!"); } } //THAY DOI THONG TIN NHAN VIEN CO MA X void THAYDOI(Stack &s) { float tg,pt=0; int n,x; Node *p; printf("Nhap ma nhan vien can thay doi: ");scanf("%d",&n); for(p=s.top;p!=NULL;p=p->next) { if(p->infor.MNV==n) { printf("1.Thay doi ho ten nhan vien"); printf("2.Thay doi tinh trang hon nhan nhan vien"); printf("3.Thay doi so cua nhan vien"); printf("4.Thay doi trinh van hoa nhan vien"); printf("5.Thay doi ket qua nhan vien"); printf("6.Thay doi he so luong nhan vien"); printf("Moi chon chuc nang: ");scanf("%d",&x); switch(x) { case 1:printf("Moi nhap ho ten thay doi: ");fflush(stdin);gets(p->infor.Hoten);break; case 2:printf("Moi nhap tinh trang hon nhan thay doi: ");fflush(stdin);gets(p->infor.GD);break; case 3:printf("Moi nhap so thay doi: ");scanf("%d",&p->infor.Con);break; case 4:printf("Moi nhap trinh van hoa thay doi: ");fflush(stdin);gets(p->infor.TDVH);break; case 5:printf("Moi nhap ket qua lam viec thay doi: ");fflush(stdin);gets(p->infor.KQ);break; case 6:printf("Moi nhap he so luong thay doi: ");scanf("%d",&p->infor.HSL);break; } if(strcmp(p->infor.KQ,"TO")==0) { pt=pt+(5*(p->infor.HSL*1350000))/100; } if(p->infor.Con>=2) { pt=pt+(5*(p->infor.HSL*1350000))/100; } if(strcmp(p->infor.TDVH,"CH")==0) { pt=pt+(10*(p->infor.HSL*1350000))/100; } tg=pt+(p->infor.HSL*1350000); p->infor.Luong=tg; } } } //IN THONG TIN NHAN VIEN DAT KET QUA TOT void KOTO(Stack s) { Node *p; for(p=s.top;p!=NULL;p=p->next) { if(strcmp(p->infor.KQ,"TO")==0) { InNV(p->infor); } } } //TIM VA IN TTNV CO HE SO LUONG CAO NHAT void HSLCAO(Stack s) { float Max=s.top->infor.HSL; Node *p; for(p=s.top;p!=NULL;p=p->next) { if(p->infor.HSL>Max) { Max= p->infor.HSL; } } for(p=s.top;p!=NULL;p=p->next) { if(p->infor.HSL==Max) { InNV(p->infor); } } } //TIM VA IN TTNV CHUA CO CON void NoKID(Stack s) { Node *p; for(p=s.top;p!=NULL;p=p->next) { if(p->infor.Con==0) { InNV(p->infor); } } } int main() { int n; Node *p; NV x; Stack s; Initstack(s); { printf("\n[ -CHUC NANG ]"); printf("\n1 Nhap danh sach"); printf("\n2 In danh sach"); printf("\n3 Tim nhan vien co ma x"); printf("\n4 Tim va in thong tin nhan vien co luong cao nhat"); printf("\n5 Tim va in thong tin nhan vien co luong thap nhat"); printf("\n6 Tim va in thong tin nhan vien co so > 3"); printf("\n7 Sap xep nhan vien theo so luong tang dan"); printf("\n8 Sap xep nhan vien theo so luong giam dan"); printf("\n9 Xoa mot nhan vien khoi danh sach"); printf("\n10 In phan tu dung dau danh sach"); printf("\n11 Dem so nhan vien co luong tren trieu"); printf("\n12 Dem so nhan vien co bang cap Dai hoc"); printf("\n13 Doi ten NV co ma x"); printf("\n14 Tim nhan vien theo ten"); printf("\n15 Tim in thong tin nhan vien co bang cap cao hoc"); printf("\n16 Tim nhan vien chua ket hon"); printf("\n17 Thay doi thong tin nhan vien"); printf("\n18 In thong tin nhan vien co ket qua lam viec tot"); printf("\n19 Tim va in thong tin nhan vien co he so luong cao nhat"); printf("\n20 Tim va in thong tin nhan vien chua co con"); printf("\nMoi ban chon chuc nang: ");scanf("%d",&n); switch(n) { case 1:NhapDSNV(s);break; case 2:InDSNV(s);break; case 3:TimNV(s);break; case 4:NVLUONGCAO(s);break; case 5:NVLUONGTHAP(s);break; case 6:Con3(s);break; case 7:SXLUONGTANG(s);break; case 8:SXLUONGGIAM(s);break; case 9:XoanV(s);break; case 10:top(s);break; case 11:DEMTREN4TRIEU(s);break; case 12:DEMNVBANGDH(s);break; case 13:DOITEN(s);break; case 14:TIMTEN(s);break; case 15:NVCAOHOC(s);break; case 16:NVS(s);break; case 17:THAYDOI(s);break; case 18:KOTO(s);break; case 19:HSLCAO(s);break; case 20:NoKID(s);break; } } while(n!=0); getch(); } ... }; //KHAI BAO CAU TRUC DU LIEU struct Node { NV infor; struct Node *next; }; //KHAI BAO DANG STACK CUA DU LIEU struct Stack { Node *top; }; //KHOI TAO STACK RONG void Initstack (Stack &s) { s.top... nhan vien co he so luong cao nhat"); printf(" 20 Tim va in thong tin nhan vien chua co con"); printf(" Moi ban chon chuc nang: ");scanf("%d",&n); switch(n) { case 1:NhapDSNV(s);break; case 2:InDSNV(s);break;... Thay!"); } else { printf("Co Tim Thay!"); } } //TIM VA IN TTNV CO BANG CAP CAO HOC void NVCAOHOC (Stack s) { Node *p; for(p=s.top;p!=NULL;p=p->next) { if(strcmp(p->infor.TDVH,"CH")==0) { InNV(p->infor);