c++课程设计:职工工资管理系统
发布网友
发布时间:2022-04-21 23:20
我来回答
共1个回答
热心网友
时间:2023-07-28 14:21
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<iomanip.h>
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<<"当前无记录!"<<endl;
return ERROR;
}
cout<<"编号"<<setw(12)<<"姓名"<<setw(12)<<"基本工资"<<setw(9)<<"奖金"<<setw(12)<<"工资总额"<<endl; while(p!=NULL)
{
cout<<p->num<<setw(9)<<p->name<<setw(8)<<p->basic<<setw(12)<<p->reward<<setw(12)<<p->total<<endl;
p=p->next;
}
cout<<'\n'<<'\n';
return OK;
} int InputInfo(LinkList &L)
{
LinkList p; p=(LinkList)malloc(sizeof(LNode));
cout<<"请输入职工工资信息:(格式如:2001001 james 1980 600 )"<<endl;
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<<"请输入要查找职工编号号:"<<endl;
cin>>num;
while(p)
{
if(strcmp(p->num,num)==0)
{
cout<<"编号"<<setw(12)<<"姓名"<<setw(12)<<"基本工资"<<setw(9)<<"奖金"<<setw(12)<<"工资总额"<<endl;
cout<<p->num<<setw(9)<<p->name<<setw(8)<<p->basic<<setw(12)<<p->reward<<setw(12)<<p->total<<endl;
cout<<'\n';
return OK;
}
p=p->next;
}
}
else if(tag==2)
{
char name[20];
cout<<"请输入要查找的姓名:"<<endl;
cin>>name;
while(p)
{
if(strcmp(p->name,name)==0)
{
cout<<"编号"<<setw(12)<<"姓名"<<setw(12)<<"基本工资"<<setw(9)<<"奖金"<<setw(12)<<"工资总额"<<endl;
cout<<p->num<<setw(9)<<p->name<<setw(8)<<p->basic<<setw(12)<<p->reward<<setw(12)<<p->total<<endl;
cout<<'\n';
return OK;
}
p=p->next;
}
}
else
cout<<"输入错误!"<<endl;
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<<"请输入要修改的职工编号号:"<<endl;
cin>>q;
while(p)
{
if(strcmp(p->num,q)==0)
{
cout<<"编号"<<setw(12)<<"姓名"<<setw(12)<<"基本工资"<<setw(9)<<"奖金"<<setw(12)<<"工资总额"<<endl;
cout<<p->num<<setw(9)<<p->name<<setw(8)<<p->basic<<setw(12)<<p->reward<<setw(12)<<p->total<<endl;
cout<<"请重新输入该职工的工资信息:"<<endl;
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:退出"<<endl;
cin>>i;
if(i==1)
{ if(InputInfo(S))
cout<<"操作成功!"<<endl;
cout<<'\n';
}
else if(i==2)
{
char num[20];
cout<<"请输入要删除的职工编号:"<<endl;
cin>>num; if(DeleteByCode(S,num))
cout<<"操作成功!"<<endl; else
{
cout<<"此编号不存在!"<<endl;
cout<<'\n';
}
}
else if(i==3)
DisplayInfo(S);
else if(i==4)
{
int tag;
cout<<"1:按编号查找 2:按姓名查找 "<<endl;
cin>>tag;
if(!Search(S,tag))
cout<<"未找到!"<<endl;
cout<<'\n'; }
else if(i==5)
{
if(Sort(S));
cout<<"操作成功!"<<endl;
cout<<'\n';
}
else if(i==6)
{
if(change(S))
cout<<"修改成功!"<<endl;
} else if(i==0)
sign=0;
else
cout<<"输入有误,请重新输入!"<<endl;
cout<<'\n';
}
return OK;
}
int main()
{
LinkList S;
initlist(S);
Menu(S);
return OK;} 已经调试无bug 有问题的话联系我。追问以工程的形式来做这个系统,不是写在一个.c中