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

📄 pro2.c

📁 字符界面的图书管理程序,用链表实现的,可以实现借书还书功能
💻 C
📖 第 1 页 / 共 2 页
字号:
 /*说明:
        1 每个月安30天计算
        2 借书日期就是当天
        3 每逾期一天罚款0.1元
        4 每人每次最多能借3本书
        5 每人最多只能借10本书
        6 必须先缴清罚款才能继续借书*/
#include "time.h"    /*时间函数*/
#include "stdio.h"   /*I/O函数*/
#include "stdlib.h"
#include "string.h"  /*字符串函数*/
#include "conio.h"   /*屏幕操作函数*/
#include "mem.h"     /*内存操作函数*/
#include "ctype.h"   /*字符操作函数*/
#include "alloc.h"   /*动态地址分配函数*/
#define BUILDBOOK (BOOK *)malloc(sizeof(BOOK))
#define BUILDMEMBER (MEMBER *)malloc(sizeof(MEMBER))

typedef struct BookList
{
   char num[20];    /*图书编号*/
   char name[15];   /*书号*/
   int  price;      /*价格*/
   int numbook;     /*管藏数*/
   int numexist;    /*可借数*/
   char person[20]; /*借阅人 */
   int yes;         /*1 存在, 0借出*/
   struct BookList *next;
}BOOK;
BOOK *headb,*tailb,*pb,*qb;
typedef struct MemberList
{
   char name[20];/*借阅人姓名*/
   char num[9]; /*借阅人证号*/
   int  count; /*可借阅图书数量*/
   char book[10][20];/*所借的书编号*/
   long bordate[10];/*借阅日期*/
   long retdate[10];/*归还日期*/
   float money;/*逾期罚款*/
   struct MemberList *next;
}MEMBER;
MEMBER *headm,*tailm,*pm,*qm;
FILE *fp;
char temp[20],ch;
void ShowMenu();       /*显示目录      */
void Addbooks();      /*输入新的链表*/
void SearchBook();
void DeleteBook();
void AddBorrower();
BOOK * BookCheck(char tem[20]);
int BookCheck1(MEMBER *h,char tem[20]);
MEMBER * GetMember(char tem[]);
void Borrow();
void Return();
void SearchBorrower();
void ShowBorrower(MEMBER * h);
void DeleteBorrower();
void PrintBorrower();
void PrintBook();
void SaveBook();
void LoadBook();
void SaveMember();
void LoadMember();
void ReturnABook(MEMBER *h,char tem[]);
void CheckFineMoney();
void CountBooks();
void PayBack(MEMBER *h);
void Others();
main()
{  
    headb=tailb=NULL;
    headm=tailm=NULL;
    LoadBook();
    LoadMember();
    CheckFineMoney();
    while(1)
    {
        ShowMenu();
        ch=getch();
        switch(ch)
        {
            case '1': Addbooks();       break;
            case '2': SearchBook();     break;
            case '3': DeleteBook();     break;
            case '4': Borrow();         break;
            case '5': Return();         break;
            case '6': AddBorrower();    break;
            case '7': SearchBorrower(); break;
            case '8': DeleteBorrower(); break;
            case '9': Others();         break;
            case '0': SaveBook();SaveMember();exit(0);
            default : continue;
        }
    }
}
void ShowMenu()
  {
   char *menu[10]={"1 Add book","2 Search book","3 Delete book infomation",
                  "4 Borrow","5 Return","6 Add borrower",
                  "7 Search borrower","8 Delete borrower","9 Others",
                  "0 Quit"};
   int i;
   textcolor(YELLOW);
   textbackground(BLUE);
   window(1,1,50,50);
   clrscr();
   gotoxy(16,1);
   printf("*******Welcome To the Library Managent System*******");
   gotoxy(25,2);
   putch(0xc9);
   for(i=0;i<31;i++)
      putch(0xcd);
   putch(0xbb);
   for(i=0;i<10;i++)
   {
       gotoxy(25,i+3);
       putch(0xba);
       cprintf("%s",menu[i]);
       gotoxy(57,i+3);
       putch(0xba);
   }
   gotoxy(25,13);
   putch(0xc8);
   for(i=0;i<31;i++)
      putch(0xcd);
   putch(0xbc);
   printf("\nSelect one to run:");
}
void Addbooks()
{
    clrscr();
    while(1)
    {
        int f;  /* 缓存分数*/
        qb=BUILDBOOK;
        printf("\nPlease input the book number:");
        scanf("%s",qb->num);
        printf("Please input the book name:");
        scanf("%s",qb->name);
        printf("Please input the book price:");
        scanf("%d",&qb->price);
        printf("%d",qb->price);
        printf("Please input the sum of the book:");
        scanf("%d",&qb->numbook);
        qb->yes=1;
        if(headb==NULL)
            headb=tailb=qb;
        else
        {
            tailb->next=qb;
            tailb=qb;
        }
        printf("another?y/n");
        ch=getch();
        if(ch=='n'||ch=='N')
            break;
    }
    tailb->next=NULL;
}
void SearchBook()        /*不完善*/
{
    int m=0;
    pb=headb;
    printf("\nplease input the bookname to search:");
    scanf("%s",temp);
    while(pb!=NULL)
    {
        if(strstr(pb->name,temp)!=NULL)
        {
            m++;
            if(m==1)    /*第一次找到*/
                 printf("\nbooknumber\t    name\t\tsum_in_lib    exist    price\n");
            printf("%-20s%-20s%-14d%-9d,%-6.2d\n",pb->num,pb->name,pb->numbook,pb->numexist,pb->price);
        }
        pb=pb->next;
    }
        if(m==0)
            printf("Cannot find,");
    printf("press any key to continue...");
    getch();
}
void DeleteBook()
{
    while(1)
    {
        printf("\nplease input the booknumber to delete:");
        scanf("%s",temp);       /*把要删除的学号存入temp数组*/
        for(pb=headb;pb!=NULL;pb=pb->next)
        {
            if(strcmp(pb->num,temp)==0)
                if(pb==headb)
                {
                    headb=pb->next;
                    free(pb);
                    break;
                }
                else
                {
                    qb->next=pb->next;
                    free(pb);
                    break;
                }
            qb=pb;
        }
        if(pb!=NULL)
            printf("It has been deleted,another to delete?:y/n(y)");
        else
            printf("Cannot find,try to delete again?:y/n(y)");
        ch=getch();
        if(ch=='N'||ch=='n')
            break;
    }
    getch();
}
void AddBorrower()
{
    while(1)
    {
        qm=BUILDMEMBER;
        printf("\nPlease input the member's name:");
        scanf("%s",qm->name);
        printf("Please input the member number:");
        scanf("%s",qm->num);
        qm->count=10;
        if(headm==NULL)
            headm=tailm=qm;
        else
        {
            tailm->next=qm;
            tailm=qm;
        }
        printf("another?y/n");
        ch=getch();
        if(ch=='n'||ch=='N')
            break;
    }
    tailm->next=NULL;
     PrintBorrower();
}
void Borrow()
{
    int i,n,a,m=0;
    long l,date;
    char temnum[20],ch;
    struct tm *tm;   /*用于日期*/
    printf("\nPlease input member's number:");
    scanf("%s",temp);
    pm=GetMember(temp);
    if(pm->money!=0)
    {
        printf("The reader must pay back fine,go to pay back fine then gborrow books?y/n(y)",pm->money);
        ch=getch();
        if(ch=='N'||ch=='n')
            return;
        else
            PayBack(pm);
        printf("press any key to continue");
    }
    while(pm!=NULL&&m<3)
    {
        printf("\nplease input the booknumber to be borrowed:\n");
        scanf("%s",temnum);
        pb=BookCheck(temnum);
        if(pb==NULL)
        {
            printf("the booknumber isnot exist\n");
            printf("Try others?y/n(y):");
            ch=getch();
            if(ch=='n'||ch=='N')
                break;
        }
        else if(pb->numexist<1)
            printf("There isnot any one in the library\n");
        else
        {
            n=pm->count;                 /*借书日期就是今天日期*/
            time(&date);
            tm=localtime(&date);
            pm->bordate[10-n]=((long)tm->tm_year+1900)*10000+(tm->tm_mon+1)*100+tm->tm_mday;
            printf("The borrow date was set today:%ld\n",pm->bordate[10-n]);
            do{
                printf("please input return data:(yyyymmdd)");
                scanf("%ld",&l);
                a=CheckDate(l);
                if(a)
                    pm->retdate[10-n]=l;
                else
                    printf("please input again\n");
            }while(!a);
            if(pm->retdate[10-n]<pm->bordate[10-n])
            {
                printf("return date should later than borrow date,please input date again.\n");
                printf("press any key to continue...");
                getch();
                continue;
            }
            strcpy(pm->book[10-n],temnum);
            pm->count--;
            pb->numexist--;
            if(pb->numexist<1)
                pb->yes=0;
        }
        m++;
        if(m==3)
        {
            printf("you reach the max(3),press any key to exit.\n");
            getch();
            break;
        }
        printf("borrow anoter one?y/n(y):");
        ch=getch();
        if(ch=='n'||ch=='N')
            break;
    }
}
BOOK * BookCheck(char tem[20])
{
    for(qb=headb;qb!=NULL;qb=qb->next)
        if(strcmp(qb->num,tem)==0)
            break;
    return qb!=NULL? qb:NULL;
}
int BookCheck1(MEMBER *h,char tem[])
{                                
    int i;
    for(i=0;i<h->count;i++)
        if(strcmp(h->book[i],tem)==0)
            return i;
    return -1;
}

MEMBER * GetMember(char tem[])
{
    MEMBER *h;
    for(h=headm;h!=NULL;h=h->next)
    {
        if(strcmp(h->num,tem)==0)
            break;
            qm=h;         /*在DeleteBorrower()函数中用到*/
    }
    if(h==NULL)
    {
        printf("The member's number isnot in database.press any key to continue...");
        getch();
    }
    return h;
}
void Return()
{
    int i;
    long l;
    char temnum[20],ch;

⌨️ 快捷键说明

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