Mọi người ơi cho em hỏi chút ạ, tại sao em không in được dữ liệu ra màn hình ạ, em không biết sai chỗ nào, mọi người giúp em với ạ! em cảm ơn!
/*
- input: int manv, char hoten, char ngaysinh, float tongluong
- output:
1. nhap danh sach ListNV nv
2. them 1 nv ao dau ds lk doi
3. tinh tong luong tat ca nhan vien trong ds
4. huy nhan vien cuoi khoi ds
5. tim nhan vien co muc luong coa nhat
6. in ds nhan vien co muc luong>2tr
7. sap xep ds tang dan manv
*/
#include<iostream>
#include<iomanip>
using namespace std;
//dn cau truc nhanvien
struct nhanvien{
int manv;
char hoten[50];
char ngaysinh[10];
float tongluong;
};
//1. tao danh sach lk doi
//dinh nghia cau truc 1 nut
struct DNode_nhanvien {
nhanvien info;
DNode_nhanvien *next;
DNode_nhanvien *prev;
};
//dn ds
struct DListnv {
DNode_nhanvien *Head;
DNode_nhanvien *Tail;
};
struct DListnv Dnv;
//khoi tao ds rong
void init(DListnv &Dnv)
{
Dnv.Head=NULL;
Dnv.Tail=NULL;
}
//tao mot nut moi
DNode_nhanvien *get_node(nhanvien nv){
DNode_nhanvien *p= new DNode_nhanvien;
if ( p== NULL )
{
cout<<"khong du bo nho";
exit(1);
}
else
{
p->info=nv;
p->next=NULL;
p->prev=NULL;
return p;
}
}
//nhap nhan vien
nhanvien nhapnv(nhanvien &nv){
cout<<"\nMa nv: "; cin>>nv.manv;
cout<<"Nhap ho ten: ";
cin>>nv.hoten;
cin.ignore();
cout<<"Nhap ngay sinh: ";
cin>>nv.ngaysinh;
cin.ignore();
cout<<"Tong luong nhan vien: ";
cin>>nv.tongluong;
return nv;
}
//hien nhan vien
void hiennv(nhanvien nv,int STT){
cout<<setw(5)<<STT<<setw(15)<<nv.manv<<setw(15)<<nv.hoten<<setw(15)<<nv.ngaysinh<<setw(15)<<setw(15)<<nv.tongluong<<endl;
}
//them vao dau
void them_dau(DListnv &Dnv, DNode_nhanvien *p){
if ( Dnv.Head == NULL )
{
init(Dnv);
}
else
{
p -> next = Dnv.Head;
Dnv.Head->prev = p;
Dnv.Head = p;
}
}
//nhap danh sach nhan vien
void nhapdsnv(DListnv &Dnv){
DNode_nhanvien *p;
int n;
nhanvien nv;
int dem=0;
cout<<"So luong nhan vien can nhap: ";cin>>n;
for(int i=0;i<n;i++){
dem++;
cout<<"\nNHAN VIEN THU "<<dem<<":";
p=get_node(nhapnv(nv));
them_dau(Dnv,p);
}
}
//hien danh sach nhan vien
void hiendsnv(DListnv Dnv)
{
int STT=0;
DNode_nhanvien *p;
cout<<setw(5)<<"STT"<<setw(15)<<"Ma nhan vien"<<setw(15)<<"Ho ten nhan vien"<<
setw(15)<<"Ngay sinh"<<setw(15)<<"Tong luong"<<endl;
p=Dnv.Head;
while(p!=NULL)
{
hiennv(p->info,STT);
p=p->next;
}
}
void hiendau(DListnv Dnv){
nhanvien nv;
DNode_nhanvien *p;
nhapnv(nv);
p = get_node(nv);
them_dau(Dnv, p);
cout<<"\nCap nhat danh sach";
hiendsnv(Dnv);
}
//tinh tong luong
void tongluong(DListnv Dnv){
float tong=0;
int n;
DNode_nhanvien *p;
nhanvien nv;
cout<<"Tong luong nhan vien: ";
for(int i=0;i<n;i++){
tong=nv.tongluong++;
cout<<tong;
}
}
//huy nhan vien cuoi
void xoa_nv_cuoi(DListnv Dnv){
DNode_nhanvien *p;
if(Dnv.Tail!=NULL){
p=Dnv.Tail;
Dnv.Tail=Dnv.Tail->next;
Dnv.Tail->next=NULL;
delete(p);
}
else
init(Dnv);
}
//nhan vien co luong cao nhat
void maxluong (DListnv Dnv)
{
DNode_nhanvien *p,*max;
int dem;
p=Dnv.Head;
max=p;
int STT=1;
while (p!=NULL)
{
if(p->info.tongluong>max->info.tongluong) { max=p; dem=0; }
if(p->info.tongluong==max->info.tongluong) { max=p; dem++; }
p=p->next;
}
cout<<"\nNV co luong cao nhat la: \n";
cout<<setw(5)<<"STT"<<setw(15)<<"Ma NV"<<setw(15)<<"Ten NV"<<setw(15)<<"Ngay sinh"<<setw(15)<<setw(15)<<"Luong"<<endl;
if(dem==0) hiennv(max->info, STT);
else
{
DNode_nhanvien *q=Dnv.Head;
while (q!=NULL)
{
if(q->info.tongluong==max->info.tongluong){
STT++;
hiennv(q->info, STT);
q=q->next;
}
}
}
}
//in danh sach nhan vien co luong >2tr
void luongtren2(DListnv Dnv){
int STT=0;
DNode_nhanvien *p;
cout<<setw(5)<<"STT"<<setw(15)<<"Ma nhan vien"<<setw(15)<<"Ho ten nhan vien"<<
setw(15)<<"Ngay sinh"<<setw(15)<<"Tong luong"<<endl;
for(DNode_nhanvien *p;p!=NULL;p=p->next){
STT++;
if(p->info.tongluong>2000000)
hiennv(p->info,STT);
}
}
//sap xep danh sach tang dan manv
void sapxep(DListnv Dnv){
int STT=0;
DNode_nhanvien *p;
cout<<setw(5)<<"STT"<<setw(15)<<"Ma nhan vien"<<setw(15)<<"Ho ten nhan vien"<<
setw(15)<<"Ngay sinh"<<setw(15)<<"Tong luong"<<endl;
nhanvien tg;
for(DNode_nhanvien *p=Dnv.Head;p!=Dnv.Tail;p=p->next)
{
for(DNode_nhanvien *q=p->next;q!=NULL;q=q->next)
{
tg=p->info;
p->info=q->info;
q->info=tg;
}
}
}
int main(){
DListnv Dnv;
init(Dnv);
DNode_nhanvien *p= new DNode_nhanvien;
int k;
do{
cout<<"==============MENU=========="<<endl;
cout<<"\n1. Nhap danh sach nhan vien ";
cout<<"\n2. Them 1 nv vao dau danh sach";
cout<<"\n3. Tong luong tat ca nhan vien trong ds ";
cout<<"\n4. Huy nhan vien cuoi khoi ds";
cout<<"\n5. tim nhan vien co muc luong coa nhat";
cout<<"\n6.in ds nhan vien co muc luong>2tr ";
cout<<"\n7. sap xep ds tang dan manv";
cout<<"\n0. Thoat";
cout<<"\nMoi ban chon: ";
cin>>k;
switch(k)
{
case 0: break;
case 1:
nhapdsnv(Dnv);break;
hiendsnv(Dnv);break;
case 2:
hiendau(Dnv);
break;
case 3:
xoa_nv_cuoi( Dnv);break;
case 4:
tongluong( Dnv);
case 5:
maxluong ( Dnv);break;
case 6:
luongtren2( Dnv);break;
case 7:
sapxep( Dnv);break;
}
}
while(k!=0);
}