|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
int n;
#define LEN sizeof(struct teacher)
struct teacher *enter();
struct teacher
{
int num;
char name[10];
char sex[10];
char unit[10];
char address[10];
long telnum;
float salary_1;
float allowance;
float life_allow;
float salary_2;
float tel_fee;
float tax;
float health_fee;
float water_fee;
float rent;
float grant;
float total_fee;
float actual_salary;
struct teacher *next;
};
int n;
struct teacher *head;
FILE *fp;
struct teacher *enter() //输入教师信息。
{
struct teacher *p1,*p2;
p1=p2=(struct teacher *)malloc(LEN);
printf("教师号:");
scanf("%d",&p1->num);fflush(stdin);
printf("教师姓名:");
gets(p1->name);
printf("教师性别:");
gets(p1->sex);
printf("教师单位:");
gets(p1->unit);
printf("教师地址:");
gets(p1->address);
printf("教师电话号码:");
scanf("%ld",&p1->telnum);fflush(stdin);
printf("教师基本工资:");
scanf("%f",&p1->salary_1);fflush(stdin);
printf("教师津贴:");
scanf("%f",&p1->allowance);fflush(stdin);
printf("教师生活补贴:");
scanf("%f",&p1->life_allow);fflush(stdin);
printf("教师个人所得税:");
scanf("%f",&p1->tax);fflush(stdin);
printf("教师电话费:");
scanf("%f",&p1->tel_fee);fflush(stdin);
printf("教师水电费:");
scanf("%f",&p1->water_fee);fflush(stdin);
printf("教师房租:");
scanf("%f",&p1->rent);fflush(stdin);
printf("教师卫生费:");
scanf("%f",&p1->health_fee);fflush(stdin);
printf("教师公积金:");
scanf("%f",&p1->grant);fflush(stdin);
p1->salary_2=p1->salary_1+p1->allowance+p1->life_allow;
p1->total_fee=p1->tax+p1->water_fee+p1->rent+p1->health_fee+p1->grant+p1->tel_fee;
p1->actual_salary=p1->salary_2-p1->total_fee;
head=NULL;
n=0;
whlie(n<20)
{ n=n+1;
if(n==1)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
p1=(struct teacher *)malloc(LEN);
printf("教师号:");
scanf("%d",&p1->num);fflush(stdin);
printf("教师姓名:");
gets(p1->name);
printf("教师性别:");
gets(p1->sex);
printf("教师单位:");
gets(p1->unit);
printf("教师地址:");
gets(p1->address);
printf("教师电话号码:");
scanf("%ld",&p1->telnum);fflush(stdin);
printf("教师基本工资:");
scanf("%f",&p1->salary_1);fflush(stdin);
printf("教师津贴:");
scanf("%f",&p1->allowance);fflush(stdin);
printf("教师生活补贴:");
scanf("%f",&p1->life_allow);fflush(stdin);
printf("教师个人所得税:");
scanf("%f",&p1->tax);fflush(stdin);
printf("教师电话费:");
scanf("%f",&p1->tel_fee);fflush(stdin);
printf("教师水电费:");
scanf("%f",&p1->water_fee);fflush(stdin);
printf("教师房租:");
scanf("%f",&p1->rent);fflush(stdin);
printf("教师卫生费:");
scanf("%f",&p1->health_fee);fflush(stdin);
printf("教师公积金:");
scanf("%f",&p1->grant);fflush(stdin);
p1->salary_2=p1->salary_1+p1->allowance+p1->life_allow;
p1->total_fee=p1->tax+p1->water_fee+p1->rent+p1->health_fee+p1->grant+p1->tel_fee;
p1->actual_salary=p1->salary_2-p1->total_fee;
}
p2->next=NULL;
return(head);
}
viod print(struct teacher *head) //打印链表
{
struct teacher *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{
printf("教师号:%d\n\n",p->num);
printf("教师姓名:%-10s\n\n",p->name);
printf("教师性别:%-6s\n\n",p->sex);
printf("教师单位名称:%-10s\n\n",p->unit);
printf("教师家庭住址:%-10s\n\n",p->address);
printf("教师电话号码:%8ld\n\n",p->telnum);
printf("教师基本工资:%5.0f\n\n",p->salary_1);
printf("教师津贴:%5.0f\n\n",p->allowance);
printf("教师生活补贴:%5.0f\n\n",p->life_allow);
printf("教师电话费:%5.0f\n\n",p->tel_fee);
printf("教师个人所得税:%5.0f\n\n",p->tax);
printf("教师卫生费:%5.0f\n\n",p->health_fee);
printf("教师水电费:%5.0f\n\n",p->water_fee);
printf("教师房租:%5.0f\n\n",p->rent);
printf("教师公积金:%5.0f\n\n",p->grant);
printf("教师应发工资:%5.0f\n\n",p->salary_2);
printf("教师合计扣款:%5.0f\n\n",p->tatal_fee);
printf("教师实发工资:%5.0f\n\n",p->actual_salary);
p=p->next;
}while(p!=NULL);
}
struct teacher *insert(struct teacher *head,struct taecher *teach) //插入函数
{
struct teacher *p0,*p1,*p2;
p1=head;
p0=teach;
if(head==NULL)
{
head=p0;
p0->next=NULL;
}
else
{
while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(head==p1)
{
head=p0;
p0->next=p1;
}
else
{
p2->next=p0;
po->next=p1;
}
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
n=n+1;
return(head);
}
struct teacher *del(struct teacher *head,int num) //删除函数
{
struct teacher *p1,*p2;
if(head==NULL)
{
printf("\nThis list is null!\n");
goto END;
}
p1=head;
while(p1->num!=num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1=head)
{
head=p1->next;
}
else
{
p2->next=p1->next;
}
printf("\nDelete NO: %d succeed!\n",num);
n=n-1;
}
else
{
printf("%d not been found!\n",num);
}
END:
return head;
}
void query(struct teacher *p) //查询函数
{
int no;
p=head;
printf("输入要查询的教师号:\n");
scanf("%d",&no);
while(p->num!=no)
p=p->next;
printf("教师号:%d\n\n",p->num);
printf("教师姓名:%-10s\n\n",p->name);
printf("教师性别:%-6s\n\n",p->sex);
printf("教师单位名称:%-10s\n\n",p->unit);
printf("教师家庭住址:%-10s\n\n",p->address);
printf("教师电话号码:%8ld\n\n",p->telnum);
printf("教师基本工资:%5.0f\n\n",p->salary_1);
printf("教师津贴:%5.0f\n\n",p->allowance);
printf("教师生活补贴:%5.0f\n\n",p->life_allow);
printf("教师电话费:%5.0f\n\n",p->tel_fee);
printf("教师个人所得税:%5.0f\n\n",p->tax);
printf("教师卫生费:%5.0f\n\n",p->health_fee);
printf("教师水电费:%5.0f\n\n",p->water_fee);
printf("教师房租:%5.0f\n\n",p->rent);
printf("教师公积金:%5.0f\n\n",p->grant);
printf("教师应发工资:%5.0f\n\n",p->salary_2);
printf("教师合计扣款:%5.0f\n\n",p->total_fee);
printf("教师实发工资:%5.0f\n\n",p->actual_salary);
}
void edit(struct teacher *p) //修改函数
{
int a;
printf("please input num:\n");
scanf("%d",&a);
printf("%d\n",a);
while(1)
{
if(p->num==a)
{
printf("教师号:%d\n\n",p->num);
printf("教师姓名:%-10s\n\n",p->name);
printf("教师性别:%-6s\n\n",p->sex);
printf("教师单位名称:%-10s\n\n",p->unit);
printf("教师家庭住址:%-10s\n\n",p->address);
printf("教师电话号码:%8ld\n\n",p->telnum);
printf("教师基本工资:%5.0f\n\n",p->salary_1);
printf("教师津贴:%5.0f\n\n",p->allowance);
printf("教师生活补贴:%5.0f\n\n",p->life_allow);
printf("教师电话费:%5.0f\n\n",p->tel_fee);
printf("教师个人所得税:%5.0f\n\n",p->tax);
printf("教师卫生费:%5.0f\n\n",p->health_fee);
printf("教师水电费:%5.0f\n\n",p->water_fee);
printf("教师房租:%5.0f\n\n",p->rent);
printf("教师公积金:%5.0f\n\n",p->grant);
printf("教师应发工资:%5.0f\n\n",p->salary_2);
printf("教师合计扣款:%5.0f\n\n",p->total_fee);
printf("教师实发工资:%5.0f\n\n",p->actual_salary);
printf("请输入新数据:\n");
printf("教师号:");
scanf("%d",&p->num);fflush(stdin);
printf("教师姓名:");
gets(p->name);
printf("教师性别:");
gets(p->sex);
printf("教师单位:");
gets(p->unit);
printf("教师地址:");
gets(p->address);
printf("教师电话号码:");
scanf("%l",&p->telnum);fflush(stdin);
printf("教师基本工资:");
scanf("%f",&p->salary_1);fflush(stdin);
printf("教师津贴:");
scanf("%f",&p->allowance);fflush(stdin);
printf("教师生活补贴:");
scanf("%f",&p->life_allow);fflush(stdin);
printf("教师个人所得税:");
scanf("%f",&p->tax);fflush(stdin);
printf("教师电话费:");
scanf("%f",&p->tel_fee);fflush(stdin);
printf("教师水电费:");
scanf("%f",&p->water_fee);fflush(stdin);
printf("教师房租:");
scanf("%f",&p->rent);fflush(stdin);
printf("教师卫生费:");
scanf("%f",&p->health_fee);fflush(stdin);
printf("教师公积金:");
scanf("%f",&p->grant);fflush(stdin);
p->salary_2=p->salary_1+p->allowance+p->life_allow;
p->total_fee=p->tax+p->water_fee+p->rent+p->health_fee+p->grant+p->tel_fee;
p->actual_salary=p->salary_2-p->total_fee;
break;
}
p=p->next;
}
}
void welcome() //装b界面,~^~
{
printf("欢迎使用教师工资管理系统,由帅哥胡孙中同志制作!!!\n\n");
}
char mainmenu()
{
char choice;
printf("教师工资管理系统\n");
printf("[1]----退出系统\n");
printf("[2]----输入教师信息\n");
printf("[3]----插入教师信息\n");
printf("[4]----删除教师信息\n");
printf("[5]----浏览教师信息\n");
printf("[6]----查询教师信息\n");
printf("[7]----修改教师信息\n");
printf("请输入您的选择:");
do
{
fflush(stdin);scanf("%c",&choice);fflush(stdin);
}while(choice<'0'||choice>'7');
}
void main()
{
struct teacher *teach;
int del_num;
char choice;
welcome();
while(1)
{
choice=mainmeun();
switch(choice)
{
case'1':
system("pause");
exit(0);
case'2':
printf("请输入新的教师信息:\n");
head=enter();
break;
case'3':
printf("请输入要插入的教师信息:\n");
teach=(struct teacher*)malloc(LEN);
printf("教师号:");
scanf("%d",&teach->num);fflush(stdin);
printf("教师姓名:");
gets(teach->name);
printf("教师性别:");
gets(teach->sex);
printf("教师单位:");
gets(teach->unit);
printf("教师地址:");
gets(teach->address);
printf("教师电话号码:");
scanf("%l",&teach->telnum);fflush(stdin);
printf("教师基本工资:");
scanf("%f",&teach->salary_1);fflush(stdin);
printf("教师津贴:");
scanf("%f",&teach->allowance);fflush(stdin);
printf("教师生活补贴:");
scanf("%f",&teach->life_allow);fflush(stdin);
printf("教师个人所得税:");
scanf("%f",&teach->tax);fflush(stdin);
printf("教师电话费:");
scanf("%f",&teach->tel_fee);fflush(stdin);
printf("教师水电费:");
scanf("%f",&teach->water_fee);fflush(stdin);
printf("教师房租:");
scanf("%f",&teach->rent);fflush(stdin);
printf("教师卫生费:");
scanf("%f",&teach->health_fee);fflush(stdin);
printf("教师公积金:");
scanf("%f",&teach->grant);fflush(stdin);
teach->salary_2=teach->salary_1+teach->allowance+teach->life_allow;
teach->total_fee=teach->tax+teach->water_fee+teach->rent+teach->health_fee+teach->grant+teach->tel_fee;
teach->actual_salary=teach->salary_2-teach->total_fee;
head=insert(head,teach);
break;
case'4':
printf("请输入要删除的教师号:\n");
scanf("%d",&del_num);
getchar();
head=del(head,del_num);
printf(head);
break;
case'5':
printf(head);
break;
case'6':
query(head);
break;
case'7':
edit(head);
break;
}
}
}
|
|