C语言 图书管理系统

C语言 图书管理系统,第1张

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("  ******************************************************nn");
	printf("  *                图书管理系统                   *n n");
	printf("  ******************************************************nn"); 
	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("编号:%10st |书名:%10st |作者:%10st |数量:%5dt |剩余库存:%5dtn",
               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("学号:%10st |名字:%10st |书籍编号:%10st |书籍名称:%10st |状态:%10sn",
               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;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5635161.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存