Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
3.2 kB
2
Indexable
Never
#include<stdio.h>
#include<iostream>
#include<string.h>
struct NhanVien
{
	char MS[16];
	char Hoten[32];
	float HSL;
	int LuongCB;
	int SoNC;
	int Luong;
};
typedef  NhanVien ElementType;
struct Node
{
	ElementType Element;
	Node* Next;	
};
typedef Node* PtrToNode;
typedef PtrToNode Position;
typedef PtrToNode List;
void MakeNullList(List &L);
int IsEmptyList(List L);
ElementType Retrieve(Position P);
void InsertList(ElementType X, Position P, List L);
//Nho dung tham chieu &
void Nhap(ElementType& X);
void NhapDS(List L);
void TinhLuong(List L);
void Xuat(ElementType X);
void XuatDS(List L);
Position Timkiem(List L, char ht[]);
void Hoanvi(ElementType&x, ElementType&y);
void Sapxep(List L);
void LietKeNC(List L);
int main()
{
	List L;
	MakeNullList(L);
	NhapDS(L);
	TinhLuong(L);
	std::cout<<"\nBang luong:\n ";
	XuatDS(L);
	char ht[32];
	std::cout<<"Nhap ho ten can tim: ";
	fflush(stdin);
	gets(ht);
	Position K= Timkiem(L,ht);
	if(K==NULL)
	{
		std::cout<<"\nKhong tim thay\n";
	}
	else
	{
		std::cout<<"\nTim thay\n";
		Xuat(K->Element);
	}
	Sapxep(L);
	std::cout<<"\nDanh sach sau khi sap xep:\n ";
	XuatDS(L);
	std::cout<<"\nDanh sach so NC>24:\n";
	LietKeNC(L);
	return 0;
}
void MakeNullList(List &L)
{
	L=new Node;
	L->Next=NULL;
}
int IsEmptyList(List L)
{
	return L->Next==NULL;
}
ElementType Retrieve(Position P)
{
	return P->Element;
}
void InsertList(ElementType X, Position P, List L)
{
	Position tempCell=new Node;
	if(tempCell==NULL)
	{
		std::cout<<"Khong du vung nho";
		return;
	}
	tempCell->Element=X;
	tempCell->Next=P->Next;
	P->Next=tempCell;
}
void Nhap(ElementType& X)
{
	std::cout<<"MS: ";
	fflush(stdin);
	gets(X.MS);
	std::cout<<"Ho ten: ";
	gets(X.Hoten);
	std::cout<<"HSL: ";
	std::cin>>X.HSL;
	std::cout<<"SoNC: ";
	std::cin>>X.SoNC;
	X.LuongCB=1150000;
}
void NhapDS(List L)
{
	int n;
	std::cout<<"So phan tu: ";
	std::cin>>n;
	Position P=L;//Them dau ds
	for(int i=0;i<n;i++)
	{
		ElementType X;
		std::cout<<"Nhap mot so nguyen: ";
		Nhap(X);
		InsertList(X,P,L);
		//P=P->Next;//Them cuoi ds. 
	}	
	
}
void TinhLuong(List L)
{
	Position P=L->Next;
	while(P!=NULL)
	{
		P->Element.Luong=P->Element.HSL*P->Element.SoNC*P->Element.Luong;
		P=P->Next;//node ke tiep
	}
}
void Xuat(ElementType X)
{
	std::cout<<X.MS<<"\t"<<X.Hoten<<"\t"<<X.Luong<<"\n";
}
void XuatDS(List L)
{
	Position P=L->Next;
	while(P!=NULL)
	{
		ElementType X=Retrieve(P);
		Xuat(X);
		P=P->Next;//node ke tiep
	}
}
Position Timkiem(List L, char ht[])
{
	Position P=L->Next;
	while(P!=NULL)
	{
		if(P->Element.Hoten==ht)
		{
			return P;
		}
		P=P->Next;//node ke tiep
	}
	return NULL;
}

void Hoanvi(ElementType&x, ElementType&y)
{
	ElementType z=x;
	x=y;
	y=z;
}
void Sapxep(List L)
{
	
	Position P,Q;
	for(P=L->Next;P!=NULL;P=P->Next)
	{
		for(Q=P->Next;Q!=NULL;Q=Q->Next)
		{
			if(P->Element.Luong>Q->Element.Luong)
			{
				Hoanvi(P->Element,Q->Element);
			}
		}
	}
}
void LietKeNC(List L)
{
	Position P=L->Next;
	while(P!=NULL)
	{
		ElementType X=Retrieve(P);
		if(X.SoNC>24)
		{
			Xuat(X);
		}
		
		P=P->Next;//node ke tiep
	}
}
Leave a Comment