📄 programe.c
字号:
void save(struct WORKER *p)
{
struct WORKER *stu;
FILE *fp;
stu=p;
if(stu==NULL)
{
printf("The List is empty!");
return;
}
fp=fopen("worker.txt","wt");
if(fp==NULL)
{
printf("The file open error!");
return;
}
printf("Wait......\n");
while(stu)
{
fputc('*\n',fp);
fprintf(fp,"%d\n",stu->num);
fprintf(fp,"%s\n",stu->name);
fprintf(fp,"%s\n",stu->sex);
fprintf(fp,"%s\n",stu->position);
fprintf(fp,"%s\n",stu->status);
fprintf(fp,"%s\n",stu->rofs);
fprintf(fp,"%s\n",stu->addr.province);
fprintf(fp,"%s\n",stu->addr.city);
fprintf(fp,"%s\n",stu->addr.street);
fprintf(fp,"%ld\n",stu->tel);
fprintf(fp,"%d,%d,%d\n%d,%d,%d\n",stu->birthday.year,stu->birthday.month,stu->birthday.day,stu->workday.year,stu->workday.month,stu->workday.day);
stu=stu->next;
}
fputc('#',fp);
fclose(fp);
printf("Success to save the file!\n");
}
void showfile(struct WORKER *head)
{
FILE *fp;
struct WORKER *p,*t,*r1,*r2,*q1,*q2;
char ch;
int i=0;
q1=head;
q2=head->next;
fp=fopen("worker.txt","r");
if(fp==NULL)
{
cprintf("File error!\npress any key to exit!...");
getch();
exit(1);
}
ch=fgetc(fp);
while(ch!='#')
{
p=(struct WORKER *)malloc(LEN);
if(i==0) r1=r2=p;
else t->next=p;
fscanf(fp,"%d\n",&p->num);
fscanf(fp,"%s\n",p->name);
fscanf(fp,"%s\n",p->sex);
fscanf(fp,"%s\n",p->position);
fscanf(fp,"%s\n",p->status);
fscanf(fp,"%s\n",p->rofs);
fscanf(fp,"%s\n",p->addr.province);
fscanf(fp,"%s\n",p->addr.city);
fscanf(fp,"%s\n",p->addr.street);
fscanf(fp,"%ld\n",&p->tel);
fscanf(fp,"%d,%d,%d\n%d,%d,%d\n",&p->birthday.year,&p->birthday.month,&p->birthday.day,&p->workday.year,&p->workday.month,&p->workday.day);
t=p;
i++;
ch=fgetc(fp);
}
if(i==0)
{
cprintf("The file is empty!\n");
getch();
return;
}
else
{
t->next=NULL;
cprintf("There is %d workers' information! \n",i);
list(r1);
}
q1->next=r2;
t->next=q2;
return;
}
struct WORKER *sort(struct WORKER *p)
{
struct WORKER *stu,*t1,*t2,*t3,*t4,*p1;
int i,j=0;
p1=(struct WORKER*)malloc(LEN);
p1->next=p;
stu=p1;
t3=stu;
t4=stu->next;
if(stu->next==NULL)
{
printf("There is no worker's information!\n");
return;
}
while(t4)
{
j=j+1;
t4=t4->next;
}
printf("there are %d workers \n",j);
t1=stu->next;
t2=t1->next;
for(i=1;i<j;i++)
{
while(t2)
{
if(t1->num<t2->num)
{
t3->next=t2;
t1->next=t2->next;
t2->next=t1;
}
t3=t3->next;
t1=t3->next;
t2=t1->next;
}
t3=stu;
t1=t3->next;
t2=t1->next;
}
stu=p1->next;
while(stu)
{
print(stu);
stu=stu->next;
getch();
}
return(p1->next);
}
void Houshuchao(void)
{
struct WORKER *p;
int m;
printf("if the worker's num is '0'input end:\n");
p=creat();
printf("----------wellcome to workers' management:-----------\n");
printf("----1.Show the workers' information ---- \n");
printf("----2.Show a worker's information ---- \n");
printf("----3.Add a new worker's information ---- \n");
printf("----4.Delet a worker information(num) ---- \n");
printf("----5.Sort the workers' information ---- \n");
printf("----6.Save the workers' information ---- \n");
printf("----7.open the file of the worker ---- \n");
printf("----8.change a worker's information ---- \n");
printf("----0.Quit the system ---- \n");
do
{
printf("input the menu number:");
scanf("%d",&m);
switch(m)
{
case 1: list(p);break;
case 2: search(p);break;
case 3: insert(p);break;
case 4: del(p);break;
case 5: p=sort(p);break;
case 6: save(p);break;
case 7: showfile(p);break;
case 8: change(p);break;
case 0: printf("end:");main();
}
}while(m!=0);
getch();
}
/*Houxiaocheng*/
typedef struct node1
{int num;
char name[20];
float price;
int CD;
char not;
struct node1 *next;
}book;
typedef struct node2
{char name[20];
int num;
char sex[5];
int lend;
int wrong;
int gread;
int classes;
struct node2 *next;
}reader;
/*添加图书的情况*/
void zengjia1(book *p)
{
book *boo,*t;
boo=(book*)malloc(sizeof(book));
/*数据录入*/
cprintf("请 输入图书信息::::");
cprintf("\n图书书号:");
scanf("%d",&boo->num);
cprintf("\n图书名字:");
scanf("%s",boo->name);
cprintf("\n图书价格:");
scanf("%f",&boo->price);
cprintf("\n是否有CD??");
scanf("%d",&boo->CD);
cprintf("\n是否在库中??----y/n");
scanf("%s",&boo->not);
t=p->next;
if(t==NULL)
{
p->next=boo;
boo->next=NULL;
}
else
{
p->next=boo;
boo->next=t;
}
}
void zengjia2(reader *p) /*增加读者信息*/
{
reader *read,*t;
read=(reader *)malloc(sizeof(reader));
/*数据录入*/
textcolor(5);
cprintf("请 输入读者信息::::");
cprintf("\n姓名:");
scanf("%s",read->name);
cprintf("\n学号:");
scanf("%d",&read->num);
cprintf("\n性别:");
scanf("%s",read->sex);
cprintf("\n已借图书:");
scanf("%d",&read->lend);
cprintf("\n违纪次数:");
scanf("%d",&read->wrong);
cprintf("\n所在班级:");
scanf("%d",&read->gread);
cprintf("\n所在年级:");
scanf("%d",&read->classes);
t=p->next;
if(t==NULL)
{
p->next=read;
read->next=NULL;
}
else
{
p->next=read;
read->next=t;
}
}
caidan()
{
int e;
cprintf("*************************************************************\n\n\n");
textcolor(14);
printf(" ");
cprintf( " 欢迎进入图书 管理栏目\n\n\n\r");
cprintf("*************************************************************\n\n\r");
printf(" ");
textcolor(2);
cprintf("1--读者信息\n\n\r");
printf(" ");
textcolor(12);
cprintf("2--图书信息\n\n\r");
}
char access()
{
char menu[]={" \n\r"
" \n\r"
" \n\r"
" \n\r"
" 1.读者信息 \n\r"
" 2.借书大厅 \n\r"
" 3.还书大厅 \n\r"
" 4.管理大厅 \n\r"
" 5.读取信息 \n\r"
" 6.退出大厅 \n\r"
" \n\r"
":\n"
};
char ch;
clrscr();
puts(menu);
ch=getch();
if(ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'&&ch!='6'&&ch!='7') return '0';
else return ch;
}
char yemian()
{
long int uu=0;
char menu[]={" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" 欢迎您!!!!!!!!!!!!!!!!!!!!! \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" 图书馆 \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
" \n\r"
":\n"
};
clrscr();
puts(menu);
for(uu=0;uu++;uu<120000);
}
void update2(reader *p)
{
reader *read;
char ch;
read=p;
clrscr();
read->lend=read->lend+1;
return;
}
void jieshu2(reader *p)
{
reader *read,*rd;
int i,n,mark=0,d;
rd=p;
read=rd->next;
if(read==NULL)
{
printf("请确定文件不空!...");
return;
}
printf("请输入你的借书卡号:\n");
scanf("%d",&i);
while(read)
{
if(read->num==i)
{
clrscr();
printf(" 你已经借了%d本书\n",read->lend);
if(read->lend==5)
{
printf("对不起 !!");
getch();
main();
}
else
{
update2(read);
mark=1;
printf("借书成功!!!");
return;
}
}
else
{
rd=rd->next;
read=read->next;
}
}
if(mark==0) printf("对不起 请确定所输入的号是否存在!");
}
void update1(book *p,reader *y)
{
book *boo;
char ch;
reader *read2;
boo=p;
read2=y;
clrscr();
printf("确定借书?——————y/n::\n");
while ((ch=getch())!='n')
{
if(ch=='y')
{
boo->not='n';
jieshu2(read2);
break;
}
else
{
printf("输入有误!");
printf("确定借书?——————y/n::\n");
break;
}
}
return;
}
void jieshu1(book *p,reader *t)
{
book *boo,*b;
int i,n,mark=0,d;
reader *read1;
read1=t;
b=p;
boo=b->next;
if(boo==NULL)
{
printf("这是空文件!...");
return;
}
printf("请输入查找的书号:\n");
scanf("%d",&i);
while(boo)
{
if(boo->num==i)
{
if(boo->not=='n')
{
printf("对不起 此书已经借出!!");
getch();
main();
}
else
{
printf("\n\n\r\n 书号:%d\n 书名:%s\n 定价:%f\n CD数:%d\n 库中还有1本书\n",boo->num,boo->name,boo->price,boo->CD);
getch();
update1(boo,read1);
saveInfo2(read1);
mark=1;
return;
}
}
else
{
p=p->next;
boo=boo->next;
}
}
if(mark==0) printf("对不起 请确定所输入的号是否存在!");
}
void downdate2(reader *p)
{
reader *read;
char ch;
read=p;
clrscr();
read->lend=read->lend-1;
return;
}
void huanshu2(reader *p)
{
reader *read,*rd;
int i,n,mark=0,d;
rd=p;
read=rd->next;
if(read==NULL)
{
printf("请确定文件不空!...");
return;
}
printf("请输入你的借书卡号:\n");
scanf("%d",&i);
while(read)
{
if(read->num==i)
{
downdate2(read);
mark=1;
saveInfo2(read);
printf("还书成功!!!");
return;
}
else
{
rd=rd->next;
read=read->next;
}
}
if(mark==0) printf("对不起 请确定所输入的号是否存在!");
}
void downdate1(book *p,reader *re)
{
book *boo;
char ch;
reader *read4;
boo=p;
read4=re;
clrscr();
printf("确定还书?——————y/n::\n");
while ((ch=getch())!='n')
{
if(ch=='y')
{
boo->not='y';
huanshu2(read4);
saveInfo2(read4);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -