其他分享
首页 > 其他分享> > 职工管理系统

职工管理系统

作者:互联网

#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<fstream>
#define MAX 100
using namespace std;
typedef struct staff
{
	char name[MAX];
	char sex[MAX];
	char birth[MAX];
	char work[MAX];
	char edu[MAX];
	char job[MAX];
	char add[MAX];
	char tel[MAX];
	struct staff* next;
}stnode,*Tst;
Tst head=new stnode;
char password[MAX]="1234abcd";
void print()
{
	if(head->next==NULL)
	{
		printf("信息表为空,不可打印!\n");
		return ;
	}
	else
	{
		printf("%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t\n","姓名","性别","出生年月","入职年月","学历","职位","地址","电话");
	    Tst p=new stnode;
		p=head->next;
		while(p)
		{
			printf("%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t%-10s\t\n",p->name,p->sex,p->birth,p->work,p->edu,p->job,p->add,p->tel);
			p=p->next;
		}
	}
}
void add()
{
	Tst p=new stnode;
	Tst q=new stnode;
	printf("请输入职工姓名:");
	scanf("%s",p->name);
	printf("请输入职工性别:");
	scanf("%s",p->sex);
	printf("请输入职工出生年月:");
	scanf("%s",p->birth);
	printf("请输入职工入职年月:");
	scanf("%s",p->work);
	printf("请输入职工学历:");
	scanf("%s",p->edu);
	printf("请输入职工职位:");
	scanf("%s",p->job);
	printf("请输入职工地址:");
	scanf("%s",p->add);
	printf("请输入职工电话:");
	scanf("%s",p->tel);
	if(head->next==NULL)
		head->next=p;
	else
	{
		q=head->next;
		while(q->next!=NULL)
		    q=q->next;
		q->next=p;
	}
}
void del()
{
	char a[MAX];
	if(head->next==NULL)
	{
		printf("信息表为空,不可删除!\n");
		return ;
	}
	printf("请输入要删除的职工信息:");
	scanf("%s",a);
	Tst p=new stnode;
	Tst q=new stnode;
	p=head->next;
	q=head;
	if(p->next==NULL&&strcmp(p->name,a)==0)
	{
		q->next=NULL;
		delete p;
	}
	else if(p->next==NULL&&strcmp(p->name,a)!=0)
	{
		printf("该职工信息不存在!\n");
		return;
	}
	else
	{
		while(p)
	    {
		    if(strcmp(p->name,a)==0)
		    {
		    	q->next=p->next;
		    	delete p;
			}
			else
			{
				p=p->next;
				q=q->next;
			}
	    }
	}
	if(p==NULL)
	{
		printf("该职工信息不存在!\n");
		return;
	}
	printf("删除成功!\n");
}
void menu()
{
	int x;
	printf("**********职工管理系统************\n");
	printf("*********1.打印职员信息************\n");
	printf("*********2.增加职员信息***********\n");
	printf("*********3.删除职员信息***********\n");
	printf("*********4.查询职员信息***********\n");
	printf("*********5.修改职员信息***********\n");
	printf("******6.按姓名排序职员信息********\n");
	printf("*************0.退出***************\n");
	while(1)
	{
		printf("请输入选项:\n");
		scanf("%d",&x);
		if(x==0) exit(0);
		if(x==1) print();
		if(x==2) add();
		if(x==3) del();
	 }
}
void power()
{
	int count=0;
	char x[MAX];
	printf("欢迎访问职工管理系统!\n");
	while(count!=5)
	{
		printf("请输入密码以继续:");
		scanf("%s",x);
		if(strcmp(password,x)==0)
		{
			printf("密码正确!\n");
			system("cls");
			return;
		}
		else
		{
			printf("密码错误!请重新输入!\n");
			count++;
		}
	}
	printf("输入错误超过5次!正在退出……\n");
	exit(0);
}
int main()
{
	power();
	menu();
}

标签:职工,管理系统,MAX,next,char,printf,10s,t%
来源: https://blog.csdn.net/m0_61464910/article/details/121937600