全部源码如下:
#include "stdio.h"
/*
level=0 means that the employee is extraordinary,and level=1 means that the
employee has been promoted.
state=0 means that the employee has been fired while state=1 means that the
employee are on duty
*/
typedef struct LNode
{
char name[20];
int level;
int state;
struct LNode *next;
}LNode;
/*main list*/
void menu(LNode *h)
{
int n;
LNode *l=h;
do{
printf("\t
STUFF MANAGE SYSTEM\n");
printf("\t1`Add new employees\n");
printf("\t2`Fire employees\n");
printf("\t3`Check employees\n");
printf("\t4`Promote employees\n");
printf("\t5`Show employe list\n");
printf("\t6`Exit\n");
/*
do
{
printf("?");
scanf("%d",&n);
switch(n)
{
case 1:add(l);break;
case 2:fire(l);break;
case 3:check(l);break;
case 4:promote(l);break;
case 5:show(l);break;
default:exit(0);
}
}
while((n<1||n>5));
*/
}
while(1);
}
/*add new employees*/
void add(LNode *l)
{
LNode *p;
int i;
printf("Input the number of employees:\n");
scanf("%d",&i);
for(;i>0;i--)
{
p=(LNode *)malloc(sizeof(LNode));
p->next=l->next;l->next=p;
gets(p->name);
p->level=0;
p->state=1;
}
}
/*fire employees*/
void fire(LNode *l)
{
char str[20];
LNode *p,*q;
int i;
p=l->next;
q=l;
printf("Input the number of fired:");
scanf("%d",&i);
printf("Input the name:\n");
for(;i>0;i--)
{
gets(str);
while(p)
if(p->name[20]==str[20]) p->state=0;
else {p=p->next;q=q->next;}
}
}
/*look for someone and check the infomation*/
void check(LNode *l)
{
char str[20];
LNode *p;
p=l->next;
printf("Input the name of being checked(end with #):");
gets(str);
while(str[0]!='#')
{
while(p)
if(p->name[20]==str[20])
{
printf("level:%d
state:",p->level);
if(p->state==1) puts("employed\n");
else puts("fired\n");
}
else p=p->next;
gets(str);
}
}
/*change the level*/
void promote(LNode *l)
{
char str[20];
LNode *p;
p=l->next;
printf("Input the name of being promoted(end with #):");
gets(str);
while(str[0]!='#')
{
while(p)
if(p->name[20]==str[20]) p->level++;
else p=p->next;
gets(str);
}
}
/*show stuff list*/
void show(LNode *l)
{
int m;
LNode *p;
p=l->next;
printf("\t1、List the stuff on duty\n");
printf("\t2、List the fired stuff\n");
printf("\t3、List all stuff once employed\n");
printf("?");
scanf("%d",&m);
if(m==1)
while(p)
{
if(p->state==1) printf("%s(%d)",p->name,p->level);
p=p->next;
}
else
if(m==2)
while(p)
{
if(p->state==0) printf("%s(%d)",p->name,p->level);
p=p->next;
}
else
while(p)
printf("%s(%d)(%d)",p->name,p->level,p->state);
}
int main()
{
LNode *h;
h=(LNode *)malloc(sizeof(LNode));
h->next=NULL;
menu(h);
}
请指教