a3105927218 2022-12-14 12:19 采纳率: 100%
浏览 70
已结题

关于#c++#的问题:这个用Dev C++该怎么写啊

这个图书馆信息系统用Dev C++改写一个什么样的代码,需要包含下方内容,没有一点头绪。
创建文件信息,基本信息管理,图书流通管理,图书统计,借书统计报表,图书查询

img

  • 写回答

4条回答 默认 最新

  • Minuw 2022-12-14 12:44
    关注
    
    // (1)主函数
    void main()    {    /*主函数*/
        struct library *head;
        int d, i, b;
        for(i = 0; i < 3; i++) {    
            printf("\n\n\n\n\n\n\n\n\n\n\n                           请用户输入口令:");
            scanf("%d", &d);
            if(d != 111) {
                printf("口令输入错误\n");
                if(i == 2) {
                    printf(“你已经输入3次错误口令,系统自动关闭\n”);
                    exit(0);
                }
            else
                break;
            }
            system("cls");
            
             do {
               switch(b = menu()){
                 case 1: head = creat();
                         save(head);
                         break;
                 case 2: out(head);
                         break;
                 case 3: check(head);
                          save(head);
                         break;
                 case 4: scores(head);
                         save(head);
                         out(head);
                         break;
                 case 5: del(head);
                         save(head);
                         out(head);
                         break;
                 case 6: corret(head);
                         save(head);
                         out(head);
                         break;
                 case 0: printf(“谢谢使用\n”);
                         exit(0);
                 default: printf(“你所选择功能不存在请重新选择\n”);
               }    
             }while(b != 0); 
        }
    } 
    
    // (2)菜单和初始化
    int menu() {  /*菜单*/
        char *menu[] = {"\n\n\n\n\n\n                   ========图书信息管理系统==========\n\n", 
        "                        1. 录入功能  ","2. 浏览功能 \n\n", 
        "                        3. 查询功能  ","4. 排序功能 \n\n", 
        "                        5. 删除功能  ","6. 修改功能 \n\n", 
        "                        0. 退出系统\n\n",
    "                   ==================================\n"};  
        int c, i;
        for(i = 0; i < 9; i++) 
            printf("%s",menu[i]); 
        do { 
            printf("\n                      请输入选项(0~6)并按回车键:");
            scanf("%d",&c);  
        } while(c < 0 || c > 6);
        return(c);
    }
     
    《(3)(录入函数) 》 
    int n;
    struct library *creat(void) {  /*建立链表*/
        struct library *head;
        struct library *p1, *p2;
        n = 0;
        system("cls");
        printf("                       这是录入功能请输入图书数据\n");
        p1 = p2 = (struct library *)malloc(LEN);
        head = NULL;
        while(1) {     
           printf("登录号:");
           scanf("%ld", &p1->num);
           if(p1->num != 0) {
              printf("书名:");
              scanf("%s", p1->bookname);
              printf("作者名:");
              scanf("%s", p1->author);
              printf("类型号:");
              scanf("%s", p1->type);
              printf("出版单位");
              scanf("%s", p1->publishing_house);
              printf("出版时间:");
              scanf("%s", p1->publishing_time);
              printf("价格:");
              scanf("%f", &p1->sale);
              printf("\n");
              n = n + 1;
              
              if(n == 1)
                head = p1;
              else 
                  p2->next = p1;
            
              p2 = p1;
              p1 = (struct library *)malloc(LEN);
           } else 
                   break;
        }
        p2->next = NULL;
        return(head);
    }
    
    《(4)(保存函数) 》 
    void save(struct library *head) {  /*保存文件*/   
        FILE *fp;
        if((fp = fopen("library.dat", "wb")) == NULL) {
            printf("不能打开文件\n");
            exit(0);
        }
        
        do {
           fwrite(head, sizeof(struct library), 1, fp);
           head = head->next;
        } while(head != NULL);
        fclose(fp);
        printf("\n文件已保存\n\n\n");
    } 
    
    《(5)输出函数 》 
    struct library *out(struct library *head) {  /*读入文件*/    
        FILE *fp;
        struct library *p1, *p2;
        if((fp = fopen("library.dat","rb")) == NULL) {
            printf("不能打开文件\n");
            exit(0);
        }
        fp = fopen("library.dat", "rb");
        p1 = (struct library *)malloc(LEN);
        head = p2 = p1;
        printf("\n                                图书的数据为\n");
         
        while(!feof(fp)) {
            fread(p1, sizeof(struct library), 1, fp);
            printf("      登录号:%ld", p1->num);
            printf("书名:%s", p1->bookname);
            printf("作者名:%s", p1->author);
            printf("类型号:%s", p1->type);
            printf("出版单位:%s", p1->publishing_house);
            printf("出版时间:%s", p1->publishing_time);
            printf("价格:%6.2f", p1->sale);
            printf("\n");
            if(p1->next == 0) break;
            p1 = (struct library *)malloc(LEN);
            p2->next = p1;
            p2 = p1;
        }
        p2->next = 0;
        fclose(fp);
        return(head);
    }
     
    《(6)查询函数 》 
    struct library *check(struct library *head) {  /*查询函数*/ 
        struct library *p;
        char style[10], a[10];
        printf("                      这是图书查询功能\n");
        printf("                      请输入查询的方法:");
        scanf("%s", style);
        printf("                      请输入要查询%s:",style);
        scanf("%s", a);
        printf("你所查询的数据:\n");
        if(head == NULL) {
            printf("\n该列表为空表\n");
            goto end;
        }
        p = head;
        if(p != 0) {
            if(strcmp(style, "bookname") == 0) {
                if(strcmp(a, p->bookname) == 0) {
                    printf("   登录号:%ld", p->num);
                    printf("书名:%s", p->bookname);
                    printf("作者名:%s", p->author);
                    printf("类型号:%s", p->type);
                    printf("出版单位:%s", p->publishing_house);
                    printf("出版时间:%s", p->publishing_time);
                    printf("价格:%6.2f", p->sale);
                    printf("\n");
                } else {
                    do {
                        p = p->next;
                    } while(strcmp(a, p->bookname) != 0 && p->next != NULL);
                    printf("   登录号:%ld", p->num);
                    printf("书名:%s", p->bookname);
                    printf("作者名:%s", p->author);
                    printf("类型号:%s", p->type);
                    printf("出版单位:%s", p->publishing_house);
                    printf("出版时间:%s", p->publishing_time);
                    printf("价格:%6.2f", p->sale);
                    printf("\n");
                }
            }
            
            if(strcmp(style, "author") == 0) {
                if(strcmp(a, p->author) == 0) {
                      printf("   登录号:%ld", p->num);
                     printf("书名:%s", p->bookname);
                     printf("作者名:%s", p->author);
                     printf("类型号:%s", p->type);
                     printf("出版单位:%s", p->publishing_house);
                     printf("出版时间:%s", p->publishing_time);
                     printf("价格:%6.2f", p->sale);
                     printf("\n");
                } else {
                    do {
                        p = p->next;
                    } while(strcmp(a, p->author) != 0 && p->next != NULL);
                    printf("   登录号:%ld",p->num);
                    printf("书名:%s",p->bookname);
                    printf("作者名:%s",p->author);
                    printf("类型号:%s",p->type);
                    printf("出版单位:%s",p->publishing_house);
                    printf("出版时间:%s",p->publishing_time);
                    printf("价格:%6.2f",p->sale);
                    printf("\n");
                } 
            }
        }
        end: return(head);    
    }
    
    《(7)排序函数 》 
    struct library *scores(struct library *head) {  /*排序函数*/
        struct library *p1, *p2;
        float i;
        long t;
        char a[20], b[20], c[20], d[20], e[20];
        p1 = head;
        if(head == NULL) {
            printf("该列表为空表\n");
        } else {
            while(p1 != NULL){
                p2 = p1->next;
              while(p2 != NULL) {
                   if(strcmp(p1->bookname, p2->bookname) >= 0) {
                       t = p2->num;
                       p2->num = p1->num;
                       p1->num = t;
                       i = p2->sale;
                       p2->sale = p1->sale;
                       p1->sale = i;
                       
                       strcpy(a, p2->bookname);
                       strcpy(b, p2->author);
                       strcpy(c, p2->type);
                       strcpy(d, p2->publishing_house);
                       strcpy(e, p2->publishing_time);
                       strcpy(p2->bookname, p1->bookname);
                       strcpy(p2->author, p1->author);
                       strcpy(p2->type, p1->type);
                       strcpy(p2->publishing_house, p1->publishing_house);
                       strcpy(p2->publishing_time, p1->publishing_time);
                       strcpy(p1->bookname, a);
                       strcpy(p1->author, b);
                       strcpy(p1->type, c);
                       strcpy(p1->publishing_house, d);
                       strcpy(p1->publishing_time, e);
                   }
                p2 = p2->next;
              }
              p1 = p1->next;
            }    
        }
        printf("文件已排序");
        return(head);
    } 
    
    《(8)修改函数 》 
    struct library  *corret(struct library *head) {  /*修改函数*/
        struct library *p;
        char m[10], z[10];
        int b, x;
        float y;
        printf("请输入要修改的书名:");
        scanf("%s", m);
        if(head==NULL) {
            printf("\n该列表为空表\n");
            goto end;
        }
        p = head;
        if(p != 0) {
            while((strcmp(p->bookname, m) != 0) && p->next != NULL) {
                p = p->next;
            }
            
            if(strcmp(p->bookname, m) == 0) {    
                 printf("登录号:%ld", p->num);
                 printf("书名:%s", p->bookname);
                 printf("作者名:%s", p->author);
                 printf("类型号:%s", p->type);
                 printf("出版单位:%s", p->publishing_house);
                 printf("出版时间:%s", p->publishing_time);
                 printf("价格:%6.2f", p->sale);
                 printf("\n");
                 printf("请输入要修改的类型:\n1.登录号\n2.书名\n3.作者名\n4.分类号\n5.出版单位\n6.出版时间\n7.价格\n");
                 scanf("%d", &b);
                 printf("请输入修改信息:");
                 if(b == 1) {    
                     scanf("%ld", &x);
                     p->num = x;
                 } else if (b == 7) {
                    scanf("%f", &y);
                    p->sale = y;
                 } else {
                      scanf("%s",z);
                      switch(b) {    
                         case 2: strcpy(p->bookname, z);
                                 break;
                         case 3: strcpy(p->author, z);
                                 break;
                          case 4: strcpy(p->type, z);
                                 break;
                           case 5: strcpy(p->publishing_house, z);
                                 break;
                         case 6: strcpy(p->publishing_time, z);
                                 break;
                         default:printf("发生错误\n");
                    }
                 }
            }
        }
        printf("文件已修改");
        end: return(head);
    } 
    
    《(9)删除函数 》 
    struct library *del(struct library *head) {  /*删除函数*/
        struct library *p1, *p2;
        long num;
        if(head == NULL) {
            printf("\n图书记录为空!\n");
            goto end;
        }
        printf("请输入要删除的图书数据的登录号:");
        scanf("%ld",&num);
        
        while(num != 0) {
            p1 = head;
            
            while(num != p1->num && p1->next != NULL) {
                p2 = p1;
                p1 = p1->next;
            }
            
            if(num == p1->num) {
                if(p1 == head)
                    head = p1->next;
                else 
                    p2->next = p1->next;
                printf("删除:%ld\n", num);
            } else 
                printf("%ld 找不到这个图书记录!\n", num);
            scanf("%ld", &num);
        }
        
        printf("已删除信息");
        end: return(head);
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 12月25日
  • 已采纳回答 12月17日
  • 创建了问题 12月14日

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?