C语言 图书管理系统

基本

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

思维导图

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;
}

C语言 图书管理系统

 

图书信息列表

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);
}

C语言 图书管理系统

 

图书借阅记录列表

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);
}

C语言 图书管理系统

 图书删除

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;
}

C语言 图书管理系统

 

上一篇:Dante,AES67,SMPTE ST 2110之间的关系


下一篇:手把手教你入门 Spring Boot + CAS 单点登录