#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
struct node
{
char no[12];
char name[40];
float yfgz;
struct node *link;
};
struct node *p,*p1;
void main()
{
struct node *create(struct node *);
void search(struct node *);
void fuzhi(struct node *);
void geshu(struct node *);
void print(struct node *);
struct node *head;
int g;
printf("\t\t 工资管理 \t\n");
printf("\t\t|---------------------------------------|\n");
printf("\t\t| |\n");
printf("\t\t| [1]建立工资表 |\n");
printf("\t\t| [2]查找工人工号 |\n");
printf("\t\t| [3]大于某一工资的工人个数 |\n");
printf("\t\t| [4]复制工资表 |\n");
printf("\t\t| [5]输出工资表 |\n");
printf("\t\t| [0]退出系统 |\n");
printf("\t\t| |\n");
printf("\t\t| 请先创建新表 |\n");
printf("\t\t| |\n");
printf("\t\t|---------------------------------------|\n\n\n");
head=NULL;
for(;;)
{
printf("请输入0-5:");
scanf("%d",&g);
switch(g)
{
case 0:exit(0);break;
case 1:head=create(head);break;
case 2:search(head);break;
case 3:geshu(head);break;
case 4:fuzhi(head);break;
case 5:print(head);break;
}
}
}
struct node * create(struct node *head)//创建链表函数
{
struct node *p1,*p2;
int n,i;
p1=p2=(struct node *)malloc(sizeof(struct node));
printf("\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
printf("请输入员工的个数:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("请输入第%d位员工的信息:\n",i+1);
printf("请输入工号:");
scanf("%s",&p1->no);
printf("请输入姓名:");
scanf("%s",p1->name);
printf("请输入应发工资:");
scanf("%f",&p1->yfgz);
p1->link=NULL;
if(head==NULL)
head=p1;
else
p2->link=p1;
p2=p1;
p1=(struct node *)malloc(sizeof(struct node));
}
printf("\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
return head;
}
void search(struct node *head)//查找结点函数
{
char n[12];
struct node *temp;
printf("请输入工号:");
scanf("%s",n);
temp=head;
while(temp!=NULL)
{
if(strcmp(temp->no,n)==0)
{
printf("职工编号:%s--姓名:%s--应发工资:%.1f\n",temp->no,temp->name,temp->yfgz);
break;
}
temp=temp->link;
}
if(temp==NULL)
printf("您输入的工号有误,无法查询!\n");
}
void geshu(struct node *head)//求结点个数函数
{
int count=0;
float zdgz;
struct node *temp;
temp=head;
printf("请输入一个最低工资数:");
scanf("%f",&zdgz);
while(temp!=NULL)
{
if(temp->yfgz>zdgz)
count++;
temp=temp->link;
}
printf("大于该工资数人数为%d人\n",count);
}
void fuzhi(struct node *head)//将head赋给p1
{
p=p1=(struct node *)malloc(sizeof(struct node));
p=head;
p1=p;
while(head!=NULL)
{
p=(struct node *)malloc(sizeof(struct node));
p=p->link;
head=head->link;
p=head;
}
}
void print(struct node *head)//输出函数
{
struct node *temp;
temp=head;
printf("\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
printf("-----工资表------");
printf("\n职工工号-----姓名-----应发工资-----");
while(temp!=NULL)
{
printf("\n%s----------%s----------%.1f\n",temp->no,temp->name,temp->yfgz);
temp=temp->link;
}
printf("\t\t * * * * * * * * * * * * * * * * * *\n\t\t*************************************\n");
return;
}
C语言课程设计-工资管理系统
猜你喜欢
转载自blog.csdn.net/qq_33360009/article/details/75125914
今日推荐
周排行