⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 library.c

📁 纯循环实现图书馆管理系统。具备基础功能。普通界面。入门级程序
💻 C
📖 第 1 页 / 共 5 页
字号:
            getch();

            }
        else
            {
            printf("\nISBN number : %d  book name: %s  author: %s   public  : %s\nNow we have [ %d ] These Books.",book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].publi,book[i].turefalse);
            printf("\nSORRY ! All of these books had been borrowed.\n");
            getch();
            }
        }

    else continue;
    }



    fclose(fp);
    if(p==0)
        {
        printf("\nWe CANNOT find this author,please check it.\n");
        getch();
        }

        {
        clr();
        printf("\nDo you want to input the AUTHOR name once? (Y/N)\n");
                        scanf("%s",&choise);
                        if(choise=='y'||choise=='Y')
                            {
                            clr();
                            goto ind1;
                            }
                        else
                            {
                            clr();
                            return;
                            }

    }
return;
}









bookpub()       /*书籍查找,按出版社*/
{
FILE *fp,*fp2;
char bookname[10];
char bookaut[10];
int ture,p,i,n=0;
char choise=0;



ind1:
p=0;
n=0;
fp=fopen("book.txt","r");
printf("\ninput the book public:\n");
scanf("%s",bookaut);


for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
    {

    if(strcmp(bookaut,book[i].publi)==0)
        {
        clr();
        p++;
        *bookname=*book[i].bookname;
        if(book[i].turefalse!=0)           /*书籍状态判断*/
            {
            printf("\nISBN number : %d  book name: %s  author: %s   public  : %s\nNow we have [ %d ] These Books,you can borrow it.\n\n",book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].publi,book[i].turefalse);

            fp2=fopen("record.txt","r");      /*打开借书操作数据库,调出借书的数据,查看此书被哪些人借阅*/
            for(i=0;fread(&student[i],sizeof(struct student),1,fp2)!=0;i++)
                {
                if(strcmp(student[i].lendbook,bookname)==0)
                    {
                    printf("These books had been borrowed by this card number: %d \n",student[i].cardnum);  /*出于保护隐私,这里不把卡号对应到名字上去。对应的话,用for循环再调用一次card.txt,然后寻找对应即可。*/
                    n++;
                    }
                else continue;
                }
            fclose(fp2);
            printf("\nThis book already be borrowed by  [ %d ]  peoples.\n",n);
            getch();
            }
        else
            {
            printf("\nISBN number : %d  book name: %s  author: %s   public  : %s\nNow we have [ %d ] These Books.",book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].publi,book[i].turefalse);
            printf("\nSORRY ! All of these books had been borrowed.\n");
            getch();
            }
        }

    else continue;
    }


fclose(fp);

if(p==0)

        {
        printf("\nWe CANNOT find this public,please check it.\n");
        getch();
        }


    {
     clr();
                        printf("\nDo you want to input the book name once? (Y/N)\n");
                        scanf("%s",&choise);
                        if(choise=='y'||choise=='Y')
                            {
                            clr();
                            goto ind1;
                            }
                        else
                            {
                            clr();
                            return;
                            }

    }
return;
}














delbook()         /*删除书籍*/
{
FILE *fp,*fp2;
int i,booknum;
char choice;

fp=fopen("book.txt","r");
fp2=fopen("ExFile.txt","w");
printf("Input the book ISBN NUMBER:\n");
scanf("%d",&booknum);

for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
    {
    if(booknum==book[i].booknum)
        {
        fwrite(&book[i],sizeof(struct book),1,fp2);
        }
    }
fclose(fp);
fclose(fp2);

printf("\nISBN number : %d  book name: %s  author: %s   public  : %s\nNow we have [ %d ] These Books.",book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].publi,book[i].turefalse);
printf("are you sure?(Y/N)\n");
scanf("%s",&choice);

if(choice=='y'||choice=='Y')
    {
    fp=fopen("book.txt","w");
    fp2=fopen("ExFile.txt","r");

    for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
        {
        fwrite(&book[i],sizeof(struct book),1,fp);
        }
    fclose(fp);
    fclose(fp2);
    fp2=fopen("ExFile.txt","w");
    fclose(fp2);
    printf("Press any key to continue.\n");
    getch();
    return;
    }

else
    {
    printf("Press any key to continue.\n");
    getch();
    return;
    }
printf("Press any Key to exit this mode.");
getch();

return;
}



changebook()        /*修改书籍资料*/
{
FILE *fp,*fp2;
char choice;
int i,booknum;


fp=fopen("book.txt","r");
fp2=fopen("ExFile.txt","w");   /*写入到临时文件*/

printf("input the ISBN NUMBER of the book you want to change:\n");
scanf("%d",&booknum);

for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
    {
    if(booknum==book[i].booknum)
        {
        clr();
printf("\nISBN number : %d  book name: %s  author: %s   public  : %s\nNow we have [ %d ] These Books.",book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].publi,book[i].turefalse);
        printf("select what you want to change:(input 1-5)\n\n");
        printf("1 : change the ISBN number\n");
        printf("2 : change the name\n");
        printf("3 : change the author\n");
        printf("4 : change the public\n");
        printf("5 : change the number of the book we have\n");
        printf("0 :       <EXIT>\n");
        printf("Please slect one:\n");
        scanf("%s",&choice);
        clr();

        switch(choice)
            {
            case '1':
                {
                printf("input new ISBN number:\n");
                scanf("%d",&book[i].booknum);
                fwrite(&book[i],sizeof(struct book),1,fp2);
                }break;
            case '2':
                {
                printf("input new name:\n");
                scanf("%s",book[i].bookname);
                fwrite(&book[i],sizeof(struct book),1,fp2);
                }break;
            case '3':
                {
                printf("input new author:\n");
                scanf("%s",book[i].bookcreat);
                fwrite(&book[i],sizeof(struct book),1,fp2);
                }break;
            case '4':
                {
                printf("input new public:\n");
                scanf("%s",book[i].publi);
                fwrite(&book[i],sizeof(struct book),1,fp2);
                }break;
            case '5':
                {
                printf("input new number of the book we have now:\n");
                scanf("%d",&book[i].turefalse);
                fwrite(&book[i],sizeof(struct book),1,fp2);
                }break;
            case '0':
                 {
                 printf("\nPress any key to EXIT this mode.\n");
                 getch();
                 };break;

            default:printf("WRONG select!");break;
            }
        continue;

        }   /*修改结束*/


    fwrite(&book[i],sizeof(struct book),1,fp2);    /*写入修改后的结果*/
    }


fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("ExFile.txt","r");  /*从临时文件写到数据库中*/

for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
    {
    fwrite(&book[i],sizeof(struct book),1,fp);
    }
fclose(fp);
fclose(fp2);
fp2=fopen("ExFile.txt","w");
fclose(fp2);

printf("Press any key to continue.\n");
getchar();
printf("Press any Key to exit this mode.");
getch();

return;
}


















main( )                 /*主菜单函数*/
{
static int k,y;
static int key0,key1,key,test,dx;

static char *chp[ ]=            /*大菜单的选项*/
    {
    "Login(alt+A)",
    "SearchBooks(alt+F)",
    "BooksOperation(alt+B)",
    "Students(alt+S)"
    };

static char *chp1[ ]=            /*下拉菜单显示内容*/
    {
    "Login      F3",
    "Logout Alt-F3",
    "Quit   Alt-x "
    };

static char *chp3[ ]=
    {
    "Show all books",
    "",
    "By Name",
    "By Author",
    "By ISBN Num",
    "By Public"
    };

static char *chp4[ ]=
    {
    "Borrow Books",
    "Return Books",

    "",
    "Adds Books",
    "Delete Books",
    "Modifile Books"
    };

static char *chp5[ ]=
    {
    "All Student",
    "FindByName",
    "FindByCardNum",
    "Add student",
    "Del student",
    "Modif student"
    };

static char buf[16*20*2],buf1[16*2];


index:

key0=key1=0;
textbackground(BLUE);





clrscr();
window(1,2,80,24);
textbackground(BLUE);
textcolor(WHITE);

clrscr();
    {printf("\n\n\n\n\n\n");
    printf(" ******************************************************************************\n");
    printf(" ******************************************************************************\n");
    printf(" ***                                                                        ***\n");
    printf(" ***  ---- Welcome to use this Library Management Operation System !  ----  ***\n");
    printf(" ***                                                                        ***\n");
    printf(" ******************************************************************************\n");
    printf(" ******************************************************************************\n");
    printf("\n\n                    Press  [ ALT+X ]  to exit this System ");

    }

window(1,25,80,25);
textbackground(BLUE);
textcolor(WHITE);
clrscr();
printf(" Version Beta 1.00E  Copy Right 2004  design by ChenQu CS0312   SN:012003016625");




window(1,1,80,1);
textbackground(WHITE);
textcolor(BLACK);

clrscr();
window(1,1,80,2);

for(k=0;k<4;k++)       /*主标题框设置,数字代表有几个*/
    cprintf("   %s",chp[k]);

dx=0;
while(1)
    {
    key=0;
    while(bioskey(1)==0);
    key=bioskey(0);
    key=key&0xff?0:key>>8;

    if(key==45) exit(0);





    if(key==30)             /*press alt+a ,建立新的下拉窗口修改此值*/
        {
        int dy,delta;
        dy=6;             /*下拉菜单个数+3 建立新的下拉窗口修改此值*/
        dx=1;               /*开始横坐标 建立新的下拉窗口修改此值*/
        delta=15;            /*黑色线条边框偏移设置 建立新的下拉窗口修改此值*/
        textbackground(BLACK);
        textcolor(WHITE);
        gotoxy(dx+3,1);
        cprintf("%s",chp[0]);     /*显示对应的大菜单的选项,是第几个选项就将0改成N-1,建立新的下拉窗口修改此值*/
        gettext(4+dx,2,19+dx,dy,buf);
        window(4+dx,2,19+dx,dy);
        textbackground(WHITE);
        textcolor(BLACK);
        clrscr();
        window(4+dx,2,19+dx,dy+1);
        gotoxy(1,1);
        putch(0xda);
        for(k=2;k<dx+delta;k++) putch(0xc4);     /*print '-'*/
            putch(0xbf);
        for(k=2;k<dy-1;k++)                /*print '|'*/
            {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -