[原创]不求加分只求共大家参考!
企业单位职工工资管理程序 :程序清单:
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
#define NULL 0
#define LEN sizeof(struct person)
struct person
{ char name[6];
long int id;
int money;
int total;
int handout;
int kouchu;
struct person *next;
};
int n;
char ch[6];
struct person *creat()
{int i;
struct person *head,*p1,*p2;n=0;
p1=p2=(struct person *)malloc(LEN);
printf("请输入人员档案:(输入!结束)\n");
printf("姓名:");
scanf("%s",ch);
head=NULL;
while (strcmp(ch,"!")!=0)
{p1=(struct person *)malloc(LEN);
strcpy(p1->name,ch);
printf("职工号:");
scanf("%ld",&p1->id);
printf("工资:");
scanf("%d",&p1->money);
printf("扣除:");
scanf("%d",&p1->kouchu);
if(n==0) head=p1;
else p2->next=p1;
p2=p1;n++;
printf("姓名:");
scanf("%s",ch);
}
p2->next=NULL;
return (head);
}
void output(struct person *head)
{struct person *p;
int i=0;
printf("*---------------------------------------------------------*\n");
printf("|序号 姓 名 职工号 工资 扣除 总计 实发 | \n");
printf("*---------------------------------------------------------*\n");
p=head;
if(head!=NULL)
do{i++;
printf("| %-d\t %s\t %ld\t %4d\t %d\t %4d\t %4d |\n",i,p->name,p->id,p->money,p->kouchu,(p->money-p->kouchu),(p->money-p->kouchu));
printf("*---------------------------------------------------------*\n");
p=p->next;
}while(p!=NULL);
}
count(struct person *head)
{if(head==NULL)return(0);
else return(1+count(head->next));
}
struct person *insert(struct person *head)
{struct person *p1,*p2,*p3;
printf("请输入新职工的档案情况!\n");
p1=(struct person *)malloc(LEN);
printf("姓名:");
scanf("%s",p1->name);
printf("职工号:");
scanf("%ld",&p1->id);
printf("工资:");
scanf("%d",&p1->money);
printf("扣除:");
scanf("%d",&p1->kouchu);
p2=head;
if(head==NULL)
{head=p1;p1->next=NULL;}
else {while((p1->id>p2->id)&&(p2->next!=NULL))
{p3=p2;
p2=p2->next;}
if(p1->id<=p2->id)
{if(head==p2){p1->next=head;head=p1;}
else {p3->next=p1;p1->next=p2;}
}
else{p2->next=p1;p1->next=NULL;}
}
n++;return(head);
}
struct person *delete (struct person *head,long int num)
{struct person *p1,*p2;
printf("要删除的职工号为:%ld\n",num);
if(head==NULL){printf("这是一个空表,没有可删除的职工号!\n");return(head);}
else{p1=head;
while(num!=p1->id&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(num==p1->id)
{if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("删除号为%ld的职工\n",num);
n--;}
else printf("没找到号为%d的职工\n",num);
return(head);
}
}
main()
{struct person *head,pers;
long i;
int k;
printf("企业单位职工工资管理程序\n");
do{printf(" ->主菜单<-\n");
printf("************************\n");
printf("|1.建立全体职工的档案 |\n");
printf("|2.输出全体职工的档案 |\n");
printf("|3.统计全体职工的人数 |\n");
printf("|4.添加职工档案 |\n");
printf("|5.删除职工档案 |\n");
printf("|6.退出本程序 |\n");
printf("************************\n");
printf("请输入选择号(1--6):");
scanf("%d",&k);
switch(k)
{ case 1:head=creat();break;
case 2:printf("本单位职工的人数为:%d人\n",count(head));output(head);break;
case 3:printf("本单位职工的人数为:%d人\n",count(head)); break;
case 4:head=insert(head);printf("\n调整后本单位的职工人数为:%d人\n",count(head));output(head); break;
case 5:printf("请输入要删除的职工号!\n");scanf("%ld",&i);head=delete(head,i);output(head); break;
default:break;
}
}while(k!=6);
}