用C语言设计职工工资管理系统

2024-12-17 04:27:22
推荐回答(1个)
回答1:

#include
#include
#include
#include
using namespace std;
#define OK 1
#define ERROR 0
typedef struct LNode{
char num[20];
char name[20];
double basic;
double reward;
double total;
struct LNode *next;
}LNode,*LinkList; int initlist(LinkList &L)
{ L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
return OK;
} int DisplayInfo(LinkList L)
{
LinkList p=L->next;
if(!p)
{
cout<<"当前无记录!"< return ERROR;
}
cout<<"编号"< {
cout<num<name<basic<reward<total< p=p->next;
}
cout<<'\n'<<'\n';
return OK;
} int InputInfo(LinkList &L)
{
LinkList p; p=(LinkList)malloc(sizeof(LNode));
cout<<"请输入职工工资信息:(格式如:2001001 james 1980 600 )"< cin>>p->num;
cin>>p->name;
cin>>p->basic;
cin>>p->reward;
p->total=p->basic+p->reward;
p->next=L->next;
L->next=p; return OK;
}int DeleteByCode(LinkList &L,char key[])
{
LinkList p=L,q;
while(p->next!=NULL)
{
if(strcmp(p->next->num,key)==0)
{
q=p->next;
p->next=q->next;
free(q);
return OK;
}
p=p->next;
}
return ERROR;} int Search(LinkList L,int tag)
{
LinkList p=L->next;
if(tag==1)
{
char num[20];
cout<<"请输入要查找职工编号号:"< cin>>num;
while(p)
{
if(strcmp(p->num,num)==0)
{
cout<<"编号"< cout<num<name<basic<reward<total< cout<<'\n';
return OK;
}
p=p->next;
}
}
else if(tag==2)
{
char name[20];
cout<<"请输入要查找的姓名:"< cin>>name;
while(p)
{
if(strcmp(p->name,name)==0)
{
cout<<"编号"< cout<num<name<basic<reward<total< cout<<'\n';
return OK;
}
p=p->next;
}
}
else
cout<<"输入错误!"< return ERROR;}
int Sort(LinkList &L)
{
LinkList p;

LinkList q,min,w=L;
for(p=L->next;p->next;p=p->next)
{
min=p;
for(q=p->next;q;q=q->next) if(min->total>q->total)
min=q; if(min!=p)
{ strcpy(w->num,p->num);
strcpy(w->name,p->name);
w->basic=p->basic;
w->reward=p->reward;
w->total=p->total;
strcpy(p->num,min->num);
strcpy(p->name,min->name);
p->basic=min->basic;
p->reward=min->reward;
p->total=min->total;
strcpy(min->num,w->num);
strcpy(min->name,w->name);
min->basic=w->basic;
min->reward=w->reward;
min->total=w->total; }
}
return OK;
}
int change(LinkList &L)
{
LinkList p=L->next;

char q[20];
cout<<"请输入要修改的职工编号号:"< cin>>q;
while(p)
{
if(strcmp(p->num,q)==0)
{
cout<<"编号"< cout<num<name<basic<reward<total< cout<<"请重新输入该职工的工资信息:"< cin>>p->basic;
cin>>p->reward;
cout<<'\n';
return OK;
}
p=p->next;
}
}
int Menu(LinkList &S)
{
int sign=1;
while(sign)
{
int i;
cout<<"请选择要进行的操作:1:插入 2:删除 3:输出 4:查找 5:排序 6:修改 0:退出"< cin>>i;
if(i==1)
{ if(InputInfo(S))
cout<<"操作成功!"< cout<<'\n';
}
else if(i==2)
{
char num[20];
cout<<"请输入要删除的职工编号:"< cin>>num; if(DeleteByCode(S,num))
cout<<"操作成功!"< {
cout<<"此编号不存在!"< cout<<'\n';
}
}
else if(i==3)
DisplayInfo(S);
else if(i==4)
{
int tag;
cout<<"1:按编号查找 2:按姓名查找 "< cin>>tag;
if(!Search(S,tag))
cout<<"未找到!"< cout<<'\n'; }
else if(i==5)
{

if(Sort(S));
cout<<"操作成功!"< cout<<'\n';
}
else if(i==6)
{
if(change(S))
cout<<"修改成功!"< } else if(i==0)
sign=0;
else
cout<<"输入有误,请重新输入!"< cout<<'\n';
}
return OK;
}
int main()
{
LinkList S;
initlist(S);
Menu(S);
return OK;} 已经调试无bug 有问题的话联系我。