• 工资管理系统


    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<malloc.h>
    
    typedef struct
    {
    	long num;
    	char name[10];
    	char date[15];
    	double pay;
    }employee;
    typedef struct node
    {
    	employee p;
    	struct node *pre;
    	struct node *next;
    }node, *linklist;
    linklist head, last;
    void setdata(linklist p)
    {
    	printf("编号:");
    	scanf("%ld", &p->p.num);
    	printf("姓名:");
    	scanf("%s", p->p.name);
    	printf("入职日期:");
    	scanf("%s", p->p.date);
    	printf("工资:");
    	scanf("%lf", &p->p.pay);
    }
    void insert(linklist p)
    {
    	p->next = last;
    	last->pre->next = p;
    	p->pre = last->pre;
    	last->pre = p;
    }
    void add()
    {
    	char ch;
    	do
    	{
    		linklist q = (linklist)malloc(sizeof(node));
    		setdata(q);
    		insert(q);
    		printf("是否继续添加  (Y键继续)");
    		getchar();
    		scanf("%c", &ch);
    	} while (ch == 'Y' || ch == 'y');
    	system("pause");
    }
    linklist find()
    {
    	char Name[10];
    	char Date[15];
    	int i;
    	linklist a=head->next;//临时指针
    	printf("选择查询方式(1.姓名 2.入职日期)");
    	scanf("%d", &i);
    	if (i == 1)
    	{
    		printf("请输入需要查找的姓名:");
    		scanf("%s", Name);
    		while (a != last)
    		{
    			if (strcmp(Name, a->p.name) == 0)
    				break;
    			a = a->next;
    		}
    	}
    	if (i == 2)
    	{
    		printf("请输入需要查找的入职日期");
    		scanf("%s", Date);
    		while (a != last)
    		{
    			if (strcmp(Name, a->p.date) == 0)
    				break;
    			a = a->next;
    		}
    	}
    	if (a = last)
    	{
    		printf("未找到
    ");
    		system("pause");
    	}
    	return a;
    }
    void del()
    {
    	linklist a = NULL;
    	linklist q = find();
    	if (q !=last)
    	{
    		a = q->pre;//临时指针
    		q->pre->next = q->next;
    		q->next->pre = a;
    		free(q);
    	}
    	else
    		printf("管理系统未收录此信息,删除失败");
    	system("pause");
    }
    void modifydata()
    {
    	linklist a;
    	printf("请按要求输入以下信息");
    	a = find();
    	if (a != NULL)
    	{
    		setdata(a);
    		printf("修改成功");
    	}
    	else
    	{
    		printf("7管理系统未收录此信息,修改失败");
    	}
    	system("pause");
    }
    void show(linklist p)
    {
    	printf("%ld	%s	%s	%.2lf
    ", p->p.num, p->p.name, p->p.date, p->p.pay);
    }
    void sort()
    {
    	int ch;
    	linklist a = head->next,b=a->next;
    	char  x[15];
    	int y;
    	double z;
    	printf("请选择排序方式:1.工号  2.姓名 3.入职日期  4.工资
    ");
    	scanf("%d", &ch);
    	if (ch == 1)
    	{
    	for (; a != last; a = a->next)
    		for (; b != last; b = b->next)
    		{
    			if (a->p.num > b->p.num)
    			{
    				y = a->p.num;
    				a->p.num = b->p.num;
    				b->p.num = y;
    			}
    		}
    		printf("排序成功!
    ");
    		system("pause");
    	}
    	else if (ch == 2)
    	{
    		for (; a != last;a=a->next)
    			for (; b != last; b = b->next)
    			{
    				if (strcmp(a->p.name, b->p.name)>0)
    				{
    					strcpy(x, a->p.name);
    					strcpy(a->p.name, b->p.name);
    					strcpy(b->p.name, x);
    				}
    			}
    			printf("排序成功!
    ");
    	}
    	else if (ch == 3)
    	{
    		for (; a != last; a = a->next)
    			for (; b != last; b = b->next)
    			{
    				if (strcmp(a->p.date, b->p.date)>0)
    				{
    					strcpy(x, a->p.date);
    					strcpy(a->p.date, b->p.date);
    					strcpy(b->p.date, x);
    				}
    			}
    			printf("排序成功!
    ");
    	}
    	else if (ch == 4)
    	{
    		for (; a != last; a = a->next)
    		for (; b != last; b = b->next)
    		{
    			if (a->p.pay > b->p.pay)
    			{
    				z = a->p.pay;
    				a->p.pay = b->p.pay;
    				b->p.pay = z;
    			}
    		}
    		printf("排序成功!
    ");
    	}
    	else
    		printf("输入有误7
    ");
    }
    void Tongji()
    {	
    	linklist a = head->next;
    	printf("工号	姓名	入职日期	工资
    ");
    	while (a != last)
    	{
    		show(a);
    		a = a->next;
    	}
    	system("pause");
    }
    void meun(void)
    {
    	printf("**********工资管理系统**********
    ");
    	printf("*           1.添加             *
    ");
    	printf("*           2.删除             *
    ");
    	printf("*           3.查询             *
    ");
    	printf("*           4.修改             *
    ");
    	printf("*           5.统计             *
    ");
    	printf("*           6.排序             *
    ");
    	printf("*           0.退出             *
    ");
    	printf("********************************
    ");
    }
    int choose()
    {
    	int i;
    	scanf("%d", &i);
    	switch (i)
    	{
    	case 1:add(); break;
    	case 2: del(); break;
    	case 3: {linklist a = find(); if (a != last){ show(a); system("pause"); } break; }
    	case 4: modifydata(); break;
    	case 5: Tongji(); break;
    	case 6: sort(); break;
    	case 0: printf("欢迎使用本系统!"); break;
    		default:printf("输入有误!,请重新操作!7");
    		break;
    	}
    	return i;
    }
    void destroy()
    {
    	linklist p = head->next;
    	while (p != last)
    	{
    		head->next = p->next;
    		free(p);
    		p = head->next;
    	}
    	free(head);
    	free(last);
    }
    int main()
    {
    	int i=1;
    	head = (linklist)malloc(sizeof(node));
    	last = (linklist)malloc(sizeof(node));
    	head->next = last;
    	last->next = NULL;
    	head->pre = NULL;
    	last->pre = head;
    	while (i=1)
    	{
    		meun();
    		i = choose();
    		system("cls");
    	}
    	system("pause");
    	destroy();
    	return 0;
    }

  • 相关阅读:
    Hiho----无间道之并查集
    Linux之压缩与解压
    Linux之用户和用户组
    Linux之关机/重启命令及一些符号
    Linux之基本操作命令
    Linux之vi/vim
    解决eclipse中maven报错Failed to read artifact descriptor for xxxx:jar
    CentOS 7下 solr 单机版安装与配置
    CentOS 7下 Tomcat7 安装与配置
    CentOS 7下 JDK 1.7 安装与配置
  • 原文地址:https://www.cnblogs.com/chenny3/p/10226254.html
Copyright © 2020-2023  润新知