?? programe.c
字號(hào):
}
else
{
printf("Your input is error!");
printf("確定還書(shū)?——————y/n::\n");
break;
}
}
return;
}
void huanshu1(book *p,reader *k)
{
book *boo2,*b2;
int i,n,mark=0,d;
reader *read3;
read3=k;
b2=p;
boo2=b2->next;
if(boo2==NULL)
{
printf("這是空文件!...");
return;
}
printf("請(qǐng)輸入書(shū)號(hào):\n");
scanf("%d",&i);
while(boo2)
{
if(boo2->num==i)
{
downdate1(boo2,read3);
mark=1;
return;
}
else
{
p=p->next;
boo2=boo2->next;
}
}
if(mark==0) printf("對(duì)不起 請(qǐng)確定所輸入的號(hào)是否存在!");
}
/*刪除圖書(shū)信息(按書(shū)號(hào))*/
shanchu1(book *p)
{
book* boo,*t;
int i,mark=0;
char ch;
t=p;
boo=t->next;
if(boo==NULL)
{
printf("The List is empty!...");
return;
}
printf("Please enter the num of the student:\n");
scanf("%d",&i);
while(boo)
{
if(boo->num==i)
{
printf("Really delet it?(Y or N):\n");
ch=getch();
if(ch=='Y'||ch=='y')
{
printf("Wait......\n");
t->next=boo->next;
free(boo);
mark=1;
printf("Success delet the book's information!");
}
else return;
}
else
{
t=t->next;
boo=boo->next;
}
}
if(mark==0) printf("The book of this num is not exit!");
}
shanchu2(reader *p)
{
reader *read,*t;
int i,mark=0;
char ch;
t=p;
read=t->next;
if(read==NULL)
{
printf("The List is empty!...");
return;
}
printf("請(qǐng)輸入學(xué)號(hào):\n");
scanf("%d",&i);
while(read)
{
if(read->num==i)
{
printf("Really delet it?(Y or N):\n");
ch=getch();
if(ch=='Y'||ch=='y')
printf("Wait......\n");
t->next=read->next;
free(read);
mark=1;
printf("Success delet the book's information!");
}
else return;
}
else
{
t=t->next;
read=read->next;
}
}
if(mark==0) printf("The reader of this num is not exit!");
}
/*保存圖書(shū)的整個(gè)鏈表信息到文件中*/
void saveInfo1(book *p)
{
book *boo;
FILE *fp;
boo=p->next;
if(boo==NULL)
{
printf("The List is empty!");
return;
}
fp=fopen("cheng.txt","wt");
if(fp==NULL)
{
printf("The file open error!");
return;
}
if(boo==NULL)
{
printf("The list is empty!");
fputc('#',fp);
fclose(fp);
return;
}
printf("Wait......\n");
while(boo)
{
fputc('*',fp);
fprintf(fp,"%d\n%s\n%f\n%d\n%c\n",boo->num,boo->name,boo->price,boo->CD,boo->not);
boo=boo->next;
}
fputc('#',fp);
fclose(fp);
printf("Success to save the file!\n");
}
saveInfo2(reader *p) /*保存讀者的整個(gè)鏈表信息到文件中*/
{
reader *read;
FILE *fp;
read=p->next;
if(read==NULL)
{
printf("The List is empty!");
return;
}
fp=fopen("hou.txt","wt");
if(fp==NULL)
{
printf("The file open error!");
return;
}
if(read==NULL)
{
printf("The list is empty!");
fputc('#',fp);
fclose(fp);
return;
}
printf("Wait......\n");
while(read)
{
fputc('*',fp);
fprintf(fp,"%s\n%d\n%s\n%d\n%d\n%d\n%d\n",read->name,read->num,read->sex,read->lend,read->wrong,read->gread,read->classes);
read=read->next;
}
fputc('#',fp);
fclose(fp);
printf("Success to save the file!\n");
}
/*釋放整個(gè)鏈表*/
void freeinfo1(book *p)
{
book *boo,*t;
boo=p->next;
while(boo)
{
t=boo;
boo=boo->next;
free(t);
}
free(p);
}
/*釋放整個(gè)鏈表*/
void freeinfo2(reader *p)
{
reader *read,*t;
read=p->next;
while(read)
{
t=read;
read=read->next;
free(t);
}
free(p);
}
/*函數(shù)從文件中調(diào)數(shù)據(jù)上來(lái)*/
void duqu1(book *boo)
{
FILE *fp;
book *p,*q;
char ch;
int i=0;
q=boo;
fp=fopen("cheng.txt","r");
if(fp==NULL)
{
printf("File error!\npress any key to exit!...");
getch();
exit(1);
}
ch=fgetc(fp);
while(ch!='#')
{
p=(book *)malloc(sizeof(book));
fscanf( fp,"%d\n%s\n%f\n%d\n%c\n",&p->num,p->name,&p->price,&p->CD,&p->not);
q->next=p;
i++;
q=p;
p++;
ch=fgetc(fp);
}
if(i==0)
{
printf("The file is empty!\npress any key to continue...");
getch();
return;
}
else
{
q->next=NULL;
printf("There is %d book' information!\npress any key...",i);
getch();
return;
}
}
void duqu2(reader *read)
{
FILE *fp;
reader *r,*y;
char ch;
int i=0;
y=read;
fp=fopen("hou.txt","r");
if(fp==NULL)
{
printf("File error!\npress any key to exit!...");
getch();
exit(1);
}
ch=fgetc(fp);
while(ch!='#')
{
r=(reader *)malloc(sizeof(reader)); fscanf( fp,"%s\n%d\n%s\n%d\n%d\n%d\n%d\n",r->name,&r->num,r->sex,&r->lend,&r->wrong,&r->gread,&r->classes);
y->next=r;
i++;
y=r;
r++;
ch=fgetc(fp);
}
if(i==0)
{
printf("The file is empty!\npress any key to continue...");
getch();
return;
}
else
{
y->next=NULL;
printf("There is %d readers' information!\npress any key...",i);
getch();
return;
}
}
/*圖書(shū)的基本情況顯示出來(lái)*/
void jutixinxi1(book *p)
{
book *boo;
boo=p->next;
if(boo==NULL)
{
printf("The List is empty!...");
return;
}
while(boo)
{
printf("**********\n");
textcolor(7);
printf(" 圖書(shū)號(hào)---:%d\n \n\r書(shū)名--:%s\n \n\r定價(jià)---:%f\n \n\rCD數(shù):%d\n ",boo->num,boo->name,boo->price,boo->CD);
if(boo->not=='y') cprintf(" \n\r在庫(kù)中可借");
if(boo->not=='n') cprintf(" \n\r已經(jīng)借出");
printf("**********\n");
boo=boo->next;
getch();
clrscr();
}
}
/*讀者的基本情況顯示出來(lái)*/
void jutixinxi2(reader *p)
{
reader *read;
read=p->next;
if(read==NULL)
{
textcolor(6);
cprintf("The List is empty!...");
return;
}
while(read)
{
printf("**********\n");
textcolor(12);
cprintf(" 姓名------:%s\n \r\n 借書(shū)號(hào):%d\n\r\n 性別------:%s\n\r\n 已借圖書(shū)------:%d\n\r\n 違紀(jì)次數(shù)--------:%d\n\r\n %d 級(jí)%d 班\n\r\n ",read->name,read->num,read->sex,read->lend,read->wrong,read->classes,read->gread);
printf("**********\n");
read=read->next;
getch();
clrscr();
}
}
Houxiaocheng()
{
int x;
int a1,a2;
char e;
char ch,mark;
book *p;
reader *u;
x=sin(0.0);
p=(book *)malloc(sizeof(book));
p->next=NULL;
u=(reader *)malloc(sizeof(reader));
u->next=NULL;
textbackground(9);
clrscr();
yemian();
duqu1(p);
duqu2(u);
ch=access();
while (ch=access())
{
switch(ch)
{
case '0':
textcolor(4);
cprintf("輸入錯(cuò)誤!Press any key contiune...");
getch();
break;
case '1':
duqu2(u);
jutixinxi2(u);
textcolor(0);
cprintf("\nPress any key to continue!...");
getch();
break;
case '2':
jieshu1(p,u);
textcolor(3);
cprintf("\nPress any key to continue!...");
getch();
break;
case '3':
huanshu1(p,u);
textcolor(5);
printf("\nPress any key to continue!...");
getch();
break;
case '4':
{
clrscr();
caidan();
scanf("%d",&e);
switch(e)
{
case 1:
printf("歡迎進(jìn)入讀者信息查詢(xún)欄");
textcolor(14);
cprintf("\n\n\r 1--增加讀者\(yùn)n\n \r 2--刪除讀者信息\n\n \r 3--顯示讀者信息\n\n\r\n");
scanf("%d",&a1);
switch (a1)
{
case 1:
zengjia2(u);
saveInfo2(u);
getch();
break;
case 2:
shanchu2(u);
saveInfo2(u);
getch();
break;
case 3:
jutixinxi2(u);
getch();
clrscr();
break;
default : textcolor(8);cprintf("輸入有誤 請(qǐng)重新輸入"); break;
}
break;
case 2:
cprintf("歡迎進(jìn)入圖書(shū)信息欄 ");
cprintf("\n\n\r\n\n\r1----增加圖書(shū)\n\n\r\n\n\r2----刪除圖書(shū)\n\n\r\n\n\r3----顯示所有圖書(shū)信息\n\n\r\n");
scanf("%d",&a2);
clrscr();
switch (a2)
{
case 1:
zengjia1(p);
saveInfo1(p);
clrscr();
getch();
break;
case 2:
shanchu1(p);
saveInfo1(p);
clrscr();
getch();
break;
case 3:
jutixinxi1(p);
getch();
clrscr();
break;
default:printf("輸入有誤 請(qǐng)重新輸入");
}
break;
}
printf("\nPress any key to continue!...");
getch();
break;
}
case '5':
duqu1(p);
clrscr();
duqu2(u);
getch();
break;
case '6':
saveInfo1(p);
printf("test1");
saveInfo2(u);
printf("test2");
freeinfo1(p);
freeinfo2(u);
main();
}
}
getch();
}
main()
{
char ch;
textcolor(15);
textbackground(0);
clrscr();
printf("歡迎進(jìn)入我們的程序!\n");
printf("您想選擇誰(shuí)的程序?(請(qǐng)輸入序號(hào))\n");
printf("1.段磊(組長(zhǎng))\n2.陳新峰\n3.段偉\n4.侯曉成\n5.侯樹(shù)超\n0.退出\n");
while ((ch=getch())!='0')
{
clrscr();
switch(ch)
{
case '1':
printf("您選擇了段磊的程序.\n");
Duanlei();
break;
case '2':
printf("您選擇了陳新峰的程序.\n");
Chenxinfeng();
break;
case '3':
printf("您選擇了段偉的程序.\n");
Duanwei();
break;
case '4':
printf("您選擇了侯曉成的程序.\n");
Houxiaocheng();
break;
case '5':
printf("您選擇了侯樹(shù)超的程序.\n");
Houshuchao();
break;
default: printf("您的輸入錯(cuò)誤!\n");
}
}
printf("\n\n為了我們更好地發(fā)展,請(qǐng)注冊(cè)您的程序!");
exit();
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -