ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

C语言 图书管理系统

2021-12-01 13:03:49  阅读:119  来源: 互联网

标签:head 管理系统 st next book printf new C语言 图书


基本

  • 图书信息录入(链表头插法)
    • 图书编号
    • 图书名称
    • 作者名
    • 库存量
  • 图书信息列表(遍历链表内容)
  • 图书借阅(记录借阅人和书籍信息、判断库存够不够)
  • 图书归还(根据输入查找借阅信息,有则修改状态,无则提示返回菜单)
  • 图书借阅记录列表(遍历链表内容)
  •  图书删除(根据输入查询该图书,存在此图书且不存在借阅,满足两条件才可删除)
  •  退出

思维导图

 

代码

main函数

int main()
{
    struct book head;
    struct student st;
    int num;
    char ch;
    head.next = NULL;	//初始化
    st.next = NULL;
	load_studentfile("student.bin",&st);
	load_bookfile("book.bin",&head);

	printf("  ******************************************************\n\n");
	printf("  *                图书管理系统                   *\n \n");
	printf("  ******************************************************\n\n"); 
	printf(" 1:图书录入\n");
	printf(" 2:图书列表\n");
	printf(" 3:图书借阅\n");
	printf(" 4:图书归还\n");
	printf(" 5:图书借阅情况\n");
	printf(" 6:图书删除\n");
	printf(" 7:退出\n");
	printf("请选择菜单编号(1-7):");
    scanf("%d",&num);
    while(num != 7){
		switch(num)
		{
			case 1:book_insert(&head);break;
			case 2:book_list(head);break;
			case 3:book_list(head);book_borrow(&head,&st);break;
			case 4:return_book_list(st);book_return(&head,&st);return_book_list(st);break;
			case 5:return_book_list(st);break;
			case 6:book_list(head);book_delete(&head,st);book_list(head);break;
        }
        printf("请选择菜单编号(1-7):");
        scanf("%d",&num);
    }
    book_list(head);

    return 0;
}

图书信息录入

void book_insert(struct book *head)
{
    struct book *new_book;

    new_book = (struct book*)malloc(sizeof(struct book));

    printf("图书编号:");
    scanf("%s",new_book->id);

    printf("图书名称:");
    scanf("%s",new_book->name);

    printf("作者名:");
    scanf("%s",new_book->author);

    printf("库存量:");
    scanf("%d",&new_book->quantity);

    new_book->status = new_book->quantity;
    flushall();
    new_book->next = head->next;
    head->next = new_book;
}

 

图书信息列表

void book_list(struct book head)
{
    struct book *p;
    FILE *pf;
    pf = fopen("book.bin","w");
    p = head.next;
	printf("--------------------------------------------------------------------------------------------------------\n");
    while(p!=NULL)
    {
        printf("编号:%10s\t |书名:%10s\t |作者:%10s\t |数量:%5d\t |剩余库存:%5d\t\n",
               p->id,
               p->name,
               p->author,
               p->quantity,
               p->status);
			
        fwrite(p,sizeof(struct book),1,pf);
        p = p->next;
    }
	printf("-------------------------------------------------------------------------------------------------------- \n");
    fclose(pf);
}

 

图书借阅记录列表

void return_book_list(struct student st)
{
    struct student *p;
    FILE *pf;
    pf = fopen("student.bin","w");
    p = st.next;

	printf("---------------------------------------------------------------------------------------------------------\n");
    while(p!=NULL)
    {
        printf("学号:%10s\t |名字:%10s\t |书籍编号:%10s\t |书籍名称:%10s\t |状态:%10s\n",
               p->sno,
               p->name,
               p->id,
               p->bookname,
               p->status == 1 ? "未还" : "已还");
        fwrite(p,sizeof(struct student),1,pf);
        p = p->next;
    }
	printf("---------------------------------------------------------------------------------------------------------\n");
    fclose(pf);
}

 图书删除

void book_delete(struct book *head, struct student st){
    char book_id[5];
    struct book *p,*p1;
    struct student *new_st;
    new_st = st.next;
    p = head;
    p1 = head->next;
    printf("请输入需要删除的书籍id:");
    scanf("%s",book_id);
    while (p1 != NULL){
        if(strcmp(p1->id,book_id) == 0){
            while(new_st != NULL){
                if(strcmp(new_st->id,book_id)==0 && new_st->status==1){
                    printf("###删除失败,该书籍有借阅未归还情况!!!###\n");
                    return;
                }
                new_st = new_st->next;
            }
			if(p1->next == NULL){
				p->next = NULL;
				free(p1);
				printf("###删除成功!!!###\n",book_id);
				return;
			}else{
				p->next = p1->next;
				free(p1);
				printf("###删除成功!!!###\n",book_id);
				return;
			}
        }
        p1 = p1->next;
        p = p->next;
    }

	printf("书籍编号错误!!!\n");
	return;
}

 

标签:head,管理系统,st,next,book,printf,new,C语言,图书
来源: https://blog.csdn.net/qq_37149242/article/details/121651860

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有