做的有点辛苦= =虽然知道大概是用结构体和链表,但实际操作十分难。是对各种函数链表等不熟悉的原因,最后还是借鉴了别人的才有思路做。。。。。。
// 职工综合信息管理系统.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include <string>
using namespace std;
typedef struct node //定义员工结构体
{
char num[10];
char name[20];
char sex[20];
char age[5];
char position[20];
char wage[10];
char telenum[20];
char addr[50];
node *next;
}employee;
void Add(employee *L,int n) //创建函数
{
char num[10],name[20],sex[20],age[5],position[20],wage[10],telenum[20],addr[50];
int i=0,j=0,k=0;
employee *N;
while(i<n)//员工个数为n
{
cout<<"请输入第"<<i+1 <<"名员工的信息:"<<endl;
cout<<"*******************************************************************************"<<endl;
cout<<"工号<<" "<<姓名<<" "<性别<<" "<<年龄<<" "<<职位<<" "<<工资<<" "<<电话<<" "<<住址"<<endl;
cout<<"*******************************************************************************"<<endl;
cin>>num;
cin>>name;
cin>>sex;
cin>>age;
cin>>position;
cin>>wage;
cin>>telenum;
cin>>addr;
N=(employee *)malloc(sizeof(employee));
strcpy(N->num,num);
strcpy(N->name,name);
strcpy(N->sex,sex);
strcpy(N->age,age);
strcpy(N->position,position);
strcpy(N->wage,wage);
strcpy(N->telenum,telenum);
strcpy(N->addr,addr);
N->next=NULL;
L->next=N;
L=N;
i++;
}
}
void Display(employee *L) //显示函数
{ cout<<"*******************************************************************************"<<endl;
cout<<"工号<<" "<<姓名<<" "<性别<<" "<<年龄<<" "<<职位<<" "<<工资<<" "<<电话<<" "<<住址"<<endl;
while(L->next!=NULL)
{
L=L->next;
cout<<L->num<<" ";
cout<<L->name<<" ";
cout<<L->sex<<" ";
cout<<L->age<<" ";
cout<<L->position<<" ";
cout<<L->wage<<" ";
cout<<L->telenum<<" ";
cout<<L->addr<<" "<<endl;
}
cout<<"*******************************************************************************"<<endl;
if(L->next=NULL)
cout<<"当前没有员工信息!"<<endl;
}
void Show(employee *L)//显示一个节点
{
cout<<"*******************************************************************************"<<endl;
cout<<"工号<<" "<<姓名<<" "<性别<<" "<<年龄<<" "<<职位<<" "<<工资<<" "<<电话<<" "<<住址"<<endl;
cout<<L->num<<" ";
cout<<L->name<<" ";
cout<<L->sex<<" ";
cout<<L->age<<" ";
cout<<L->position<<" ";
cout<<L->wage<<" ";
cout<<L->telenum<<" ";
cout<<L->addr<<" "<<endl;
cout<<"*******************************************************************************"<<endl;
}
void Search(employee *L)//查询函数
{
char num[10];
employee *p;
p=L;
{
cout<<"请输入要查找员工的工号:"<<endl;
cin>>num;
while(L!=NULL)
{
if(strcmp(L->num,num)==0)
{
Show(L);
break;
}
else L=L->next;
}
if(L==NULL)
cout<<"不存在该员工的信息,请重新输入:"<<endl;
L=p;
}
}
void Modify(employee *L)
{
int x;
char num[10],name[20],sex[5],age[5],position[20],wage[10],telenum[20],addr[50];
cout<<"请输入要更新员工的工号:"<<endl;
cin>>num;
L=L->next;
while(L!=NULL)
{
if(strcmp(L->num,num)==0)
{
Show(L);
break;
}
else L=L->next;
}
if(L==NULL)
cout<<"查无此人,请重新输入:"<<endl;
else
{
while(1)
{
cout<<"1.修改 2.退出"<<endl;
cout<<"请选择:(1,2)"<<endl;
cin>>x;
if(x==1)
{
cout<<"请输入新数据:"<<endl;;
cin>>num;
cin>>name;
cin>>sex;
cin>>age;
cin>>position;
cin>>wage;
cin>>telenum;
cin>>addr;
strcpy(L->num,num);
strcpy(L->name,name);
strcpy(L->sex,sex);
strcpy(L->age,age);
strcpy(L->position,position);
strcpy(L->wage,wage);
strcpy(L->telenum,telenum);
strcpy(L->addr,addr);
cout<<"修改的数据为:"<<endl;
Show(L);
}
else if(x==2) break;
else
cout<<"输入有误,请重新输入:"<<endl;
}
}
}
void Delete(employee *L)
{
char num[10];
int x;
employee *p,*q,*w;
cout<<"请输入要删除员工的工号:"<<endl;
cin>>num;
w=L;
L=L->next;
while(L!=NULL)
{
if(strcmp(L->num,num)==0)
{
Show(L);
break;
}
else
{
w=L;
L=L->next;
}
}
if(L==NULL)
cout<<"查无此人,请重新输入:"<<endl;
else
{
p=w;
while(1)
{
cout<<"1.删除员工数据 2.退出"<<endl;
cout<<"请选择:(1,2)"<<endl;
cin>>x;
if(x==1)
{
q=p->next;
p->next=q->next;
free(q);
break;
}
else if(x==2)
break;
else
cout<<"输入有误,请重新输入:"<<endl;
}
}
}
int main()
{
int x,n;
employee *L;
L=(employee *)malloc(sizeof(employee));
L->next=NULL;
cout<<" "<<endl;
cout<<"***************************************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* 【 欢 迎 进 入 员 工 管 理 系 统 】 *"<<endl;
cout<<"* *"<<endl;
cout<<"* ------------------------------------------------ *"<<endl;
while(1)
{
cout<<"---------------------------------------------------------------------------"<<endl;
cout<<"* *"<<endl;
cout<<"* 1.添加 2.查询 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 3.修改 4.显示 *"<<endl;
cout<<"* *"<<endl;
cout<<"* 5.删除 6.退出 *"<<endl;
cout<<"* *"<<endl;
cout<<"----------------------------------------------------------------------------"<<endl;
cout<<" "<<endl;
cout<<"请选择:";
cin>>x;
if(x==1)
{
cout<<"请输入员工数目:"<<endl;
cin>>n;
Add(L,n);
}
else if(x==2)
{
if(L->next==NULL)
cout<<"当前没有任何员工的信息,不能进行查询!"<<endl;
else
Search(L);
}
else if(x==3)
{
if(L->next==NULL)
cout<<"当前没有任何员工的信息,不能进行修改!"<<endl;
else
Modify(L);
}
else if(x==4)
{
if(L->next==NULL)
cout<<"当前没有任何员工的信息!"<<endl;
else
{
cout<<"该员工管理系统的所有信息:"<<endl;
Display(L);
}
}
else if(x==5)
{
if(L->next==NULL)
cout<<"当前没有任何员工的信息,不能进行删除!"<<endl;
else
Delete(L);
}
else if(x==6)
{
cout<<" ************感谢您的使用************"<<endl;
}
else
cout<<"输入有误,请重新输入:"<<endl;
}
return 0;
}
主界面
测试功能