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

C语言图书信息管理系统源码

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

C语言图书信息管理系统源码

#include 
#include 
#include 
#include 
struct all{
    char category[20];
    char number[20];
    char bookname[20];
    int out;
    int noout;

    char penumber[20];
    char name[20];
    int peout;
    int maxout;
    char outbooks[30];
    struct all *next;
};
void freed(struct all *pfirst);//释放指针内存
void input();
void xiugai();
void delet();
void chazhao();
void xianshi();
void quanshan();

void jieyue();
void jieyuechaozuo();
void guihuan();
void guihuanchaozuo();
void shanchuguihuan(char str[20]);
void wodexingxi();
void shuchu();



int main() {
    int num, ex;
    printf("欢迎进入图书管理系统,按1进入管理员系统,按2进入用户系统");
    scanf("%d", &num);
    if (num == 1) {
        while (1) {
            printf("===============图书维护系统===============n");
            printf("1.新增图书n");
            printf("2.更改图书信息n");
            printf("3.删除图书n");
            printf("4.查找图书n");
            printf("5.显示所有图书信息n");
            printf("6.全删当前数据n");
            printf("0.退出n");
            printf("=================请选择===================n");
            scanf("%d", &ex);
            if (ex == 1) {
                input();
                printf("按任意键继续....");
                getch();
            } else if (ex == 2) {
                xiugai();
                printf("按任意键继续....");
                getch();
            } else if (ex == 3) {
                delet();
                printf("按任意键继续....");
                getch();
            } else if (ex == 4) {
                chazhao();
                printf("按任意键继续....");
                getch();
            } else if (ex == 5) {
                xianshi();
                printf("按任意键继续....");
                getch();
            } else if (ex == 6) {
                quanshan();
                printf("=============已经全删===========n");
                printf("按任意键继续....");
                getch();
            } else if (ex == 0) {
                break;
            }
        }
    }
    else if (num == 2) {
        char str[20];
        printf("用户请输入学号登录:");
        scanf("%s",str);
        while (1){
            printf("===============图书维护系统===============n");
            printf("1.借阅图书n");
            printf("2.归还图书n");
            printf("3.查看所有图书n");
            printf("4.查找图书n");
            printf("5.显示我的信息n");
            printf("0.退出n");
            printf("=================请选择===================n");
            scanf("%d", &ex);
            if(ex == 1){
                jieyue();
                printf("======================================n");
                printf("按任意键继续....");
                getch();
            }
            else if(ex == 2){
                guihuan();
                printf("======================================n");
                printf("按任意键继续....");
                getch();
            }
            else if(ex == 3){
                xianshi();
                printf("按任意键继续....");
                getch();
            }
            else if(ex == 4){
                chazhao();
                printf("按任意键继续....");
                getch();
            }
            else if(ex == 5){
                wodexingxi();
                printf("按任意键继续....");
                getch();
            }
            else if(ex == 0){
                break;
            }
        }
    }
}
void freed(struct all *pfirst) {
    struct all *p = pfirst;
    while (p) {
        pfirst = pfirst->next;
        free(p);
        p = pfirst;
    }
}
void input() {
    FILE *fp;
    struct all *bh;
    if ((fp = fopen("quanbu.txt", "a+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    bh = (struct all *) malloc(sizeof(struct all));
    printf("新增加图书信息,请输入:n");
    printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
    scanf("%s %s %s %d %d", bh->category, bh->number, bh->bookname, &bh->out, &bh->noout);
    fprintf(fp, "%st%st%st%dt%dn", bh->category, bh->number, bh->bookname, bh->out, bh->noout);
    free(bh);
    fclose(fp);
}
void xiugai() {
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    FILE *fp;
    int i = 0;
    char n[50];
    struct all *p;
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp = fopen("quanbu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF) {
        p = (struct all *) malloc(sizeof(struct all));
        p->next = phead->next;
        phead->next = p;
    }
    printf("输入你要修改的书号:");
    scanf("%s", n);
    rewind(fp);
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF &&
           p != NULL) {
        if (strcmp(n, p->number) == 0) {
            printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
            printf("%st%st%st%dt%dn", p->category, p->number, p->bookname, p->out, p->noout);
            printf("输入更改后的信息");
            printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
            scanf("%s %s %s %d %d", p->category, p->number, p->bookname, &p->out, &p->noout);
            printf("=================修改完毕===============n");
            i++;
            break;
        }
        p = p->next;
    }
    if (i == 0) {
        printf("无法查找到输入书号n");
        return;
    } else {
        phead = phead->next;
        rewind(fp);
        while (phead) {
            fprintf(fp, "%st%st%st%dt%dn", phead->category, phead->number, phead->bookname, phead->out,
                    phead->noout);
            phead = phead->next;
        }
    }
    fclose(fp);
    freed(p);


}
void delet() {
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    struct all *p;
    FILE *fp;
    int i = 0;
    char a[20];
    if ((fp = fopen("quanbu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    rewind(fp);
    p = (struct all *) malloc(sizeof(struct all));
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF) {
        p = (struct all *) malloc(sizeof(struct all));
        p->next = phead->next;
        phead->next = p;
    }
    printf("输入你要删除的书号:");
    scanf("%s", a);
    rewind(fp);
    FILE *fp1;
    if ((fp1 = fopen("linshi.txt", "w+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF &&
           p != NULL) {
        if (strcmp(a, p->number) == 0) {
            printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
            printf("%st%st%st%dt%dn", p->category, p->number, p->bookname, p->out, p->noout);
            printf("=================删除完毕===============n");
            i = 1;
        } else if (strcmp(a, p->number) != 0) {
            fprintf(fp1, "%st%st%st%dt%dn", p->category, p->number, p->bookname, p->out, p->noout);
        }
        p = p->next;
    }
    freed(p);
    fclose(fp);
    fclose(fp1);
    remove("quanbu.txt");
    rename("linshi.txt", "quanbu.txt");
    if (i == 0)
        printf("未查找到输入的书号n");
}
void chazhao() {
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    FILE *fp;
    int n, i = 0;
    char a[20], b[20], c[20];
    struct all *p;
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp = fopen("quanbu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF) {
        p = (struct all *) malloc(sizeof(struct all));
        p->next = phead->next;
        phead->next = p;
    }
    printf("选择查找方式:书名查找按1,类别查找按2,书号查找按3:");
    scanf("%d", &n);
    if (n == 1) {
        printf("请输入你要查找的书名:");
        scanf("%s", a);
        rewind(fp);
        while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF &&
               p != NULL) {
            if (strcmp(a, p->bookname) == 0) {
                printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
                printf("%st%st%st%dt%dn", p->category, p->number, p->bookname, p->out, p->noout);
                i++;
                break;
            }
            p = p->next;
        }
        fclose(fp);
        freed(p);
        if (i == 0)
            printf("无法查找到输入书名n");
    } else if (n == 2) {
        printf("请输入你要查找的类别:");
        scanf("%s", b);
        rewind(fp);
        while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF &&
               p != NULL) {
            if (strcmp(b, p->category) == 0) {
                printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
                printf("%st%st%st%dt%dn", p->category, p->number, p->bookname, p->out, p->noout);
                i++;
                break;
            }
            p = p->next;
        }
        fclose(fp);
        freed(p);
        if (i == 0)
            printf("无法查找到输入类别n");
    } else if (n == 3) {
        printf("请输入你要查找的书号:");
        scanf("%s", c);
        rewind(fp);
        while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF &&
               p != NULL) {
            if (strcmp(c, p->number) == 0) {
                printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
                printf("%st%st%st%dt%dn", p->category, p->number, p->bookname, p->out, p->noout);
                i++;
                break;
            }
            p = p->next;
        }
        fclose(fp);
        freed(p);
        if (i == 0)
            printf("无法查找到输入书号n");
    }
}
void xianshi() {
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    FILE *fp;
    struct all *p;
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp = fopen("quanbu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    rewind(fp);
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF) {
        p->next = phead->next;
        phead->next = p;
        p = (struct all *) malloc(sizeof(struct all));
    }
    phead = phead->next;
    printf("%st%st%st%st%sn", "图书类别", "书号", "书名", "已借出数量", "未借出数量");
    while (phead) {
        printf("%st%st%st%dt%dn", phead->category, phead->number, phead->bookname, phead->out, phead->noout);
        phead = phead->next;
    }
    fclose(fp);
    freed(phead);
}
void quanshan() {
    remove("quanbu.txt");
}

void jieyue() {
    char aw[30];
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    FILE *fp;
    FILE *fp1;
    struct all *p;
    char str[20];
    int i = 0;
    printf("====================图书借阅系统======================n");
    printf("请输入你想要借阅的书号:");
    scanf("%s", str);
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp = fopen("quanbu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF) {
        p = (struct all *) malloc(sizeof(struct all));
        p->next = phead->next;
        phead->next = p;
    }
    rewind(fp);
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF &&
           p != NULL) {
        if (strcmp(str, p->number) == 0) {
            jieyuechaozuo();
            p->out = p->out + 1;
            p->noout = p->noout - 1;
            printf("借阅成功!n");
            if ((fp1 = fopen("jieshuxiangmu.txt", "a+")) == NULL) {
                printf("can not open file!");
                exit(1);
            }
            fprintf(fp1, "%st",str);
            fclose(fp1);
            i = 1;
            break;
        }
        p = p->next;

    }
    if(i == 0) {
        printf("未查找到你想要借阅的书号n");
        return;
    }
    else{
        phead = phead->next;
        rewind(fp);
        while (phead) {
            fprintf(fp, "%st%st%st%dt%dn", phead->category, phead->number, phead->bookname, phead->out,
                    phead->noout);
            phead = phead->next;
        }
    }
    fclose(fp);
    freed(p);
}
void jieyuechaozuo(){
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    FILE *fp3;
    struct all *p;
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp3 = fopen("yonghu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
 fscanf(fp3, "%s %s %d %d n", p->penumber,p->name,&p->peout,&p->maxout);
    p->peout = p ->peout + 1;
    rewind(fp3);
        fprintf(fp3, "%st%st%dt%dn", p->penumber,p->name,p->peout,p->maxout);

    fclose(fp3);
    free(p);
}
void guihuan(){
    char aw[30];
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    FILE *fp;
    FILE *fp1;
    struct all *p;
    char str[20];
    int i = 0;
    printf("====================图书借阅系统======================n");
    printf("请输入你想要归还的书号:");
    scanf("%s", str);
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp = fopen("quanbu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF) {
        p = (struct all *) malloc(sizeof(struct all));
        p->next = phead->next;
        phead->next = p;
    }
    rewind(fp);
    while (fscanf(fp, "%s %s %s %d %dn", p->category, p->number, p->bookname, &p->out, &p->noout) != EOF &&
           p != NULL) {
        if (strcmp(str, p->number) == 0) {
            guihuanchaozuo();
            p->out = p->out - 1;
            p->noout = p->noout + 1;
            printf("归还成功!n");
            shanchuguihuan(str);
            i = 1;
            break;
        }
        p = p->next;

    }
    if(i == 0) {
        printf("未查找到你想要归还的书号n");
        return;
    }
    else{
        phead = phead->next;
        rewind(fp);
        while (phead) {
            fprintf(fp, "%st%st%st%dt%dn", phead->category, phead->number, phead->bookname, phead->out,
                    phead->noout);
            phead = phead->next;
        }
    }
    fclose(fp);
    freed(p);
}
void guihuanchaozuo(){
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    FILE *fp3;
    struct all *p;
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp3 = fopen("yonghu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    fscanf(fp3, "%s %s %d %d n", p->penumber,p->name,&p->peout,&p->maxout);
    p->peout = p ->peout - 1;
    rewind(fp3);
    fprintf(fp3, "%st%st%dt%dn", p->penumber,p->name,p->peout,p->maxout);

    fclose(fp3);
    free(p);
}
void shanchuguihuan(char str[20]){
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    struct all *p;
    FILE *fp1;
    FILE *fp;
    if ((fp1 = fopen("jieshuxiangmu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    rewind(fp1);
    p = (struct all *) malloc(sizeof(struct all));
    while (fscanf(fp1, "%s",p->outbooks) != EOF) {
        p = (struct all *) malloc(sizeof(struct all));
        p->next = phead->next;
        phead->next = p;
    }
    if ((fp = fopen("linshi.txt", "w+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    rewind(fp1);
    while (fscanf(fp1, "%s", p->outbooks) != EOF &&
           p != NULL) {
            if (strcmp(str, p->outbooks) != 0) {
            fprintf(fp, "%st", p->outbooks);
        }
        p = p->next;
    }
    freed(p);
    fclose(fp);
    fclose(fp1);
    remove("jieshuxiangmu.txt");
    rename("linshi.txt", "jieshuxiangmu.txt");

}
void wodexingxi(){
    struct all *phead;
    phead = (struct all *) malloc(sizeof(struct all));
    phead->next = NULL;
    struct all *p;
    FILE *fp;
    p = (struct all *) malloc(sizeof(struct all));
    if ((fp = fopen("yonghu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    fscanf(fp,"%s %s %d %d",p->penumber,p->name,&p->peout,&p->maxout);
    printf("%st%st%st%sn","学号","姓名","已借出数量","最大借书量");
    printf("%st%st%dt%dn",p->penumber,p->name,p->peout,p->maxout);
    printf("借书项目n");
    shuchu();
    fclose(fp);
    free(p);

}
void shuchu(){
    char ch[200];
    FILE *fp;
    if ((fp = fopen("jieshuxiangmu.txt", "r+")) == NULL) {
        printf("can not open file!");
        exit(1);
    }
    fgets(ch,200,fp);
    printf("%sn",ch);
    fclose(fp);

}


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

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

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