栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c语言课程设计(图书馆借阅系统)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c语言课程设计(图书馆借阅系统)

话不多说直接上代码。

#include
#include
#include
#include
#include
#define N 1000
#define LEN sizeof(book)

typedef struct book
{
    int num;                            //编号
    char name[31];                        //书名
    char author_name[27];                //作者名
    char chubanshe[20];                    //出版社
    int jieyucishu;                        //借阅次数
}book;

struct book temp;
struct book temp2;
int  tushuzongshu;

int luru();
void chaxun();
int shanchu();
void xiugai();
void chaxuncishu();
void tongji();

void main()
{    
    int n;
    Sleep(300);
    loop1:
    tongji();    
    printf("nntt********************************图书管理系统**************************************");
    printf("nnnttt*********欢迎使用图书馆管理系统,请选择你需要的操作**********");
    printf("nnnn当前图书馆藏书一共有%d本。",tushuzongshu);
    printf("nnntttttt1.图书录入系统");
    printf("nnntttttt2.图书查询系统");
    printf("nnntttttt3.图书删除系统");
    printf("nnntttttt4.图书修改系统");
    printf("nnntttttt5.图书借阅次数最值系统");
    printf("nnntttttt6.退出图书管理系统");
    printf("nnntttttt请选择您所需要的操作:    ");
    scanf("%d",&n);
    if(n>=1&&n<=5){
        system("ClS");
    }
    else if(n==6){
        system("ClS");
        printf("再次按下回车键退出,谢谢使用!");
    }
    else{
        system("CLS");
        goto loop1;
    }
    switch(n)
    {
        case 1:luru();goto loop1;
        case 2:chaxun();goto loop1;
        case 3:shanchu();goto loop1;
        case 4:xiugai();goto loop1;
        case 5:chaxuncishu();goto loop1;
    }
}

int luru()
{    
    FILE *fp=NULL;
    book stu;
    char flag = 'y';
    fp=fopen("book1.dat","ab+");
    
    while((flag == 'y'||flag == 'Y')){
        printf("nnnntttt****************这里是图书录入系统*******************");
        printf("n请输入图书id: ");
        scanf("%d",&stu.num);
        printf("n请输入图书书名: ");
        scanf("%s",stu.name);
        printf("n请输入图书作者: ");
        scanf("%s",stu.author_name);
        printf("n请输入图书出版社: ");
        scanf("%s",stu.chubanshe);
        stu.jieyucishu=0;
        
        fwrite(&stu,LEN,1,fp);
        fflush(stdin);
        
        printf("nnn是否继续输入?继续请输入y或Y:");
        scanf("%c",&flag);
    }
    system("CLS");
    fclose(fp);
    return;
    
}

void chaxun()
{
    FILE *fp=NULL;
    book stu;
    int n,i,j,t=-1;
    int nums;
    char name[N],authors_name[40],chubanshe1[40];
    loop3:
    fp = fopen("book1.dat","rb+");        
    printf("nnnntttt****************这里是图书查询系统*******************");
    printf("nttttt请选择你所查询的方式:");
    printf("nnttttt1.编号查询;");
    printf("nnttttt2.书名查询;");
    printf("nnttttt3.作者查询;");
    printf("nnttttt4.出版社查询;");
    printf("nnttttt5.返回主菜单;");
    printf("请输入您的选择:");
    scanf("%d",&n);
    system("CLS");
    if(n==1){
        printf("ntttttt请您输入图书编号:");
        scanf("%d",&nums);
        fseek(fp,0,SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(nums==stu.num)
            {
                t=1;
                printf("nttttt此书为%s,借阅数为%d,是否选择借阅?1.是   2.否",stu.name,stu.jieyucishu);
                printf("n请输入你的选择:");
                scanf("%d",&j);
                if(j==1){
                    stu.jieyucishu++;
                    fseek(fp,-4,SEEK_CUR);
                    fwrite(&stu.jieyucishu,sizeof(int),1,fp);
                    printf("n借阅成功!请从管理员处领取书籍。3秒钟后返回主菜单");
                    t=-1;
                    fclose(fp);
                    Sleep(3000);
                    system("CLS");
                    goto loop3;
                }
                else{
                    printf("n3秒钟后返回主菜单");
                    t=-1;
                    fclose(fp);
                    Sleep(3000);
                    system("CLS");
                    goto loop3;
                }
            }
        }
        fclose(fp);
        if(t==-1){
            printf("未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop3;
        }
    }

    else if(n==2){
        printf("nttttt请输入书名:");
        scanf("%s",&name);
        fseek(fp,0,SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(name,stu.name) == 0)
            {
                t=1;
                printf("nttttt此书为%s,借阅数为%d,是否选择借阅?1.是   2.否",stu.name,stu.jieyucishu);
                printf("n请输入你的选择:");
                scanf("%d",&j);
                if(j==1){
                    stu.jieyucishu++;
                    fseek(fp,-4,SEEK_CUR);
                    fwrite(&stu.jieyucishu,sizeof(int),1,fp);
                    printf("n借阅成功!请从管理员处领取书籍。3秒钟后返回主菜单");
                    t=-1;
                    fclose(fp);
                    Sleep(3000);
                    system("CLS");
                    goto loop3;
                }
                else{
                    printf("n3秒钟后返回主菜单");
                    t=-1;
                    fclose(fp);
                    Sleep(3000);
                    system("CLS");
                    goto loop3;
                }                
            }
        }
        fclose(fp);
        if(t==-1){
            printf("未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop3;
        }
    
    }

    else if(n==3){
        printf("nttttt请输入书作者:");
        scanf("%s",&authors_name);
        fseek(fp,0,SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(authors_name,stu.author_name) == 0){
                printf("nttttt作者的图书有%sn",stu.name);
            }
            t=1;
        }
        fclose(fp);
        if(t==-1){
            printf("nttttt未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop3;
        }
        else if(t!=-1){
            printf("nttttt是否返回主菜单?1.是  2.否");
            t=-1;
            scanf("%d",&j);
            if(j==1){
                printf("nttttt3秒钟后返回主菜单");
                Sleep(3000);
                system("CLS");
            }
            else{
                printf("nttttt3秒钟后返回主菜单");
                Sleep(3000);
                system("CLS");
            }
        }
    }
    else if(n==4){
        printf("nttttt请输入书出版社:");
        scanf("%s",&chubanshe1);
        fseek(fp,0,SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(chubanshe1,stu.chubanshe) == 0){
                printf("nttttt出版社的图书有%sn",stu.name);
            }
            t=1;
        }        
        fclose(fp);
        if(t==-1){
            printf("ttttt未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            goto loop3;
        }
        else if(t!=-1){
            printf("nttttt是否返回主菜单?1.是  2.否");
            scanf("%d",&j);
            if(j==1){
                printf("nttttt3秒钟后返回主菜单");
                Sleep(3000);
                system("CLS");
            }
            else{
                printf("nttttt3秒钟后返回主菜单");
                Sleep(3000);
                system("CLS");
            }
        }
    }
    else if(n==5){
        printf("nttttt3秒钟后返回主菜单");
        Sleep(3000);
        system("CLS");
    }
}

int shanchu()
{
    int n,i,j,t=-1;
    int nums;
    book stu;
    FILE *fp;
    
    char name[20],authors_name[40],chubanshe1[40];
    loop2:
    fp = fopen ("book1.dat","rb+");
    printf("nnnntttt****************这里是图书删除系统*******************");
    printf("ntttt请输入您想要删除的书的数据:");
    printf("ntttt1.书籍编号。");
    printf("ntttt2.书籍书名。");
    printf("ntttt3.书籍作者。");
    printf("ntttt4.书籍出版社。");
    printf("ntttt5.返回主菜单。");
    printf("ntttt请输入您的选择:");
    scanf("%d",&n);
    system("CLS");
    if(n==1){
        printf("ntttt请输入书籍编号:");
        scanf("%d",&nums);
        fseek(fp, 0, SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(nums==stu.num){
                t=1;
                printf("nttttt此书为%sn",stu.name);
                printf("ntttt是否确定删除图书%s。1.是   2.否",stu.name);
                scanf("%d",&j);
                if(j==1){
                    printf("ntttt图书删除成功");
                    printf("ntttt3秒后返回之前界面。");
                    fseek(fp,0,SEEK_SET);
                    FILE *fp1;
                    fp1 = fopen("linshi.dat","ab+");
                
                    while(fread(&stu,LEN,1,fp)){
                        if(nums!=stu.num){
                            fwrite(&stu,LEN,1,fp1);
                        }
                    }
                    fclose(fp);
                    fclose(fp1);
                    while(remove("book1.dat")!=0);
                    rename("linshi.dat","book1.dat");                    
                    fflush(stdin);
                    Sleep(3000);
                    system("CLS");
                    return;                                    
                }
                else{
                    printf("ntttt3秒后返回之前界面。");
                }
                Sleep(3000);
                system("CLS");
                
                goto loop2;                 
            }
        }
        if(t==-1){
            printf("ntttt未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop2;
        }
    }
    else if(n==2){
        printf("ntttt请输入书籍名称:");
        scanf("%s",&name);
        fseek(fp, 0, SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(name,stu.name) == 0){
                t=1;
                printf("nttttt此书为%sn",stu.name);
                printf("ntttt是否确定删除图书%s。1.是   2.否",stu.name);
                scanf("%d",&j);
                if(j==1){
                    printf("ntttt图书删除成功");
                    printf("ntttt3秒后返回主界面。");
                    fseek(fp,0,SEEK_SET);
                    FILE *fp1;
                    fp1 = fopen("linshi.dat","ab+");
                
                    while(fread(&stu,LEN,1,fp)){
                        if(strcmp(name,stu.name) != 0){
                            fwrite(&stu,LEN,1,fp1);
                        }
                    }
                    fclose(fp);
                    fclose(fp1);
                    while(remove("book1.dat")!=0);
                    rename("linshi.dat","book1.dat");
                
                    fflush(stdin);
                    Sleep(3000);
                    system("CLS");
                    return;
                }
                else{
                    printf("ntttt3秒后返回上一界面。");
                    Sleep(3000);
                    system("CLS");
                    goto loop2;
                }        
            }

        }
        if(t==-1){
            printf("ntttt未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop2;
        }
    }
    else if(n==3){
        printf("ntttt请输入书籍作者:");
        scanf("%s",&authors_name);
        fseek(fp, 0, SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(authors_name,stu.author_name) == 0){
                printf("nttttt此书为%sn",stu.name);
            }
            t=1;
        }
        fclose(fp);        
        if(t==-1){
            printf("ntttt未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop2;
        }
        else if(t!=-1){
            printf("ntttt请确认好需要删除图书的书名,返回上次界面从新选择删除方式。ntttt3秒后返回之前界面。");    
            Sleep(3000);
            system("CLS");
            goto loop2;
        }
    }
    else if(n==4){
        printf("ntttt请输入书籍出版社:");
        scanf("%s",&chubanshe1);
        fseek(fp, 0, SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(chubanshe1,stu.chubanshe) == 0){
                printf("nttttt此书为%sn",stu.name);
            }
            t=1;
        }
        fclose(fp);    
        if(t==-1){
            printf("ntttt未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop2;
        }
        else if(t!=-1){
            printf("ntttt请确认好需要删除图书的书名,返回上次界面从新选择删除方式。ntttt3秒后返回之前界面。");    
            Sleep(3000);
            system("CLS");
            goto loop2;
        }
    }
    else if(n==5){
        printf("ntttt3秒钟后返回主菜单");
        Sleep(3000);
        system("CLS");    
    }
}
 
void xiugai(){
    book stu;
    FILE *fp;
    int n,m,t=-1;
    int nums;
    char name[N],authors_name[40],chubanshe1[40];
    loop4:
    fp = fopen("book1.dat","rb+");
    printf("nnnntttt****************这里是图书修改系统*******************");
    printf("nttttt请选择你所需要修改图书的信息:");
    printf("nnttttt1.编号;");
    printf("nnttttt2.书名;");
    printf("nnttttt3.作者;");
    printf("nnttttt4.出版社;");
    printf("nnttttt5.返回主菜单;");
    printf("nnttttt请输入您的选择:");    
    scanf("%d",&n);
    system("CLS");
    if(n==1){
        printf("nnttttt请输入修改图书的编号:");
        scanf("%d",&nums);
        fseek(fp, 0, SEEK_SET);
        while (fread(&stu, LEN, 1, fp))
        {

            if (nums==stu.num)
            {
                printf("nnttttt请重新输入图书编号:   ");
                scanf("%d", &stu.num);
    
                printf("nnttttt请重新输入书名:    ");
                scanf("%s", &stu.name);

                printf("nnttttt请重新输入书籍作者: ");
                scanf("%s", &stu.author_name);

                printf("nnttttt请重新输入图书出版社: ");
                scanf("%s", &stu.chubanshe);

                fflush(stdin);
                fseek(fp, 0-LEN, SEEK_CUR);
                fwrite(&stu, LEN, 1, fp);
                fclose(fp);
            }
        }
        printf("ntttt图书修改完成,3秒钟后返回主菜单");
        Sleep(3000);
        system("CLS");
    }
    if(n==2){
        printf("nnttttt请输入修改图书的书名:");
        scanf("%s",&name);
        fseek(fp, 0, SEEK_SET);
        
        while (fread(&stu, LEN, 1, fp))
        {

            if (strcmp(name,stu.name) == 0)
            {
                printf("请重新输入图书id:   ");
                scanf("%d", &stu.num);

                printf("请重新输入书名:    ");
                scanf("%s", &stu.name);

                printf("请重新输入书籍作者  : ");
                scanf("%s", &stu.author_name);
    
                printf("请重新输入图书出版社  : ");
                scanf("%s", &stu.chubanshe);

                fflush(stdin);
                fseek(fp,0-LEN, SEEK_CUR);
                fwrite(&stu, LEN, 1, fp);
                fclose(fp);
            }
        }
        printf("ntttt图书修改完成,3秒钟后返回主菜单");
        Sleep(3000);
        system("CLS");        
    }
    if(n==3){
        printf("ntttt请输入作者名称:");
        scanf("%s",&authors_name);
        fseek(fp, 0, SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(authors_name,stu.author_name) == 0){
                printf("nttttt此出版社的图书为%sn",stu.name);
            }
            t=1;
        }
        fclose(fp);
        if(t==-1){
            printf("未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop4;
        }
        else if(t!=-1){
            printf("n3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop4;
            }                            
        }
    
    if(n==4){
        printf("ntttt请输入出版社名称:");
        scanf("%s",&chubanshe1);
        fseek(fp, 0, SEEK_SET);
        while(fread(&stu,LEN,1,fp)){
            if(strcmp(chubanshe1,stu.chubanshe) == 0){
                printf("nttttt此出版社的图书为%sn",stu.name);
            }
            t=1;
        }
        fclose(fp);
        if(t==-1){
            printf("未找到您所需要的书籍,3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop4;
        }
        else if(t!=-1){
            printf("n3秒后返回上一界面。");
            Sleep(3000);
            system("CLS");
            goto loop4;
            }
        }
    if(n==5){
        printf("n3秒后返回主菜单。");
        Sleep(3000);
        system("CLS");
    }
}

void chaxuncishu()
{
    FILE *fp;
    book stu;
    int min=10000,max=0,m;
    loop7:
    fp = fopen("book1.dat","rb+");
    fseek(fp, 0, SEEK_SET);
    while (fread(&stu,LEN,1,fp)){
        if(stu.jieyucishu>=max){
            max=stu.jieyucishu;
            strcpy(temp.name,stu.name);    
        }
        if(stu.jieyucishu<=min&&stu.jieyucishu>=0){
            min=stu.jieyucishu;
            strcpy(temp2.name,stu.name);
        }
    }
    fclose(fp);
    printf("nntt******************这里是图书借阅次数最值界面*********************");
    printf("nntt******************图书借阅次数最多的图书为:%s,借阅次数为:%d********************",temp.name,max);
    printf("nntt******************图书借阅次数最少的图书为:%s,借阅次数为:%d********************",temp2.name,min);
    printf("nntt******************是否返回主菜单?1.是 2.否********************");
    scanf("%d",&m);
    if(m==1){
        printf("nntt******************3秒后返回主菜单。***********************");
        Sleep(3000);
        system("CLS");
    }
    else if(m==2){
        system("CLS");
        goto loop7;
    }            
}

void tongji(){
    FILE *fp;
    book stu;
    tushuzongshu=0;
    fp = fopen("book1.dat","rb+");
    fseek(fp, 0, SEEK_SET);
    while(fread(&stu,LEN,1,fp)){
        tushuzongshu++;
    }
    fclose(fp);    
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1000785.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号