Java用链表写图书管理_C语言链表实现图书管理系统

之前参照网上的资料用链表实现了图书管理系统,包括简单的增删改查功能以及借书还书功能,我是VC6.0下写的一个控制台程序,格式参照的网上的。在动手编码之前,你需要理清自己的思路。首先,需要确定图书馆里系统中主要有那几个对象,这里我写了学生对象和图书对象。不妨在纸上写出或画出它们主要包括哪些属性以及其可能的对应关系,这里根据不同人的要求会有所不同。清楚这些之后,就可以设计学生和图书的数据结构,比如这里我用的结构体存储其信息。然后就需要考虑,我想要哪些功能,除了基本的增删改查之外,我还想要哪些功能?比如借书、还书,我怎么表示这之间的关系?可以通过图书的属性来记录该书的状态,及是否被借走,谁借了。主要就是这个思路,图书的增删改查是通过链表实现的,当然也可以用数组实现,只不过那会浪费较多的空间。

// MyLibManSys.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include "iostream"

struct book{

int id;

char title[20];

char author[20];

double price;

char state[20];

int student_id;

char student_name[20];

struct book* next;

};

struct student{

int id;

char name[20];

char sex[10];

char borrow_book[30];

struct student* next;

};

void Print_Book(struct book *head_book);

void Print_Student(struct student *head_student);

struct book *Create_New_Book();/*创建新的图书库*/

struct student *Create_New_Student();/*创建新的学生库*/

struct book *Insert_Book(struct book *head_book,struct book *new_book);/*增加图书,逐个添加*/

//void Insert_Book(struct book *head_book,struct book *new_book);/*增加图书,逐个添加*/

//函数的参数是一个指针时,不要在函数体内部改变指针所指的地址,那样毫无作用,需要修改的只能是指针所指向的内容。即应把指针当作常量

struct student *Insert_Student(struct student *head_student,struct student *new_student);/*增加学生,逐个添加*/

struct book *Search_Book_ById(int id,struct book *head_book);

struct book *Search_Book_ByTitle(char *title,struct book *head_book);

struct book *Search_Book_ByPrice(double price_h,double price_l,struct book *head_book);

//bool Delete_Book(int id,book* head_book);

struct book* Delete_Book(int id,book* head_book);

struct student *Search_Student(int id,struct student *head_student);

struct student* Delete_Student(int id,student* head_student);

void Lent_Book(int id,int student_id,struct book *head_book,struct student *head_student);

void Back_Book(int id,int student_id,struct book *head_book,struct student *head_student);

int main()

{

struct book* head_book,*p_book;

struct student* head_student, *p_student;

int choice, f, id, student_id;

int m = 1;

char name[20],sex[10];

char title[20];

double price_h,price_l,price;

char author[20];

int size_book=sizeof(struct book);

int size_student=sizeof(struct student);

printf("\n欢迎您第一次进入图书管理系统!\n\n");

printf("----->[向导]----->[新建图书库]\n\n");

printf("注意:当输入图书编号为0时,进入下一步.\n\n");

head_book=Create_New_Book();

system("cls");

//Print_Book(head_book);

printf("\n欢迎您第一次进入图书管理系统!\n\n");

printf("----->[向导]----->[新建会员库]\n\n");

printf("注意:当输入会员学号为0时,进入主菜单.\n\n");

head_student=Create_New_Student();

system("cls");

//Print_Student(head_student);

do{

printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");

printf("\n");

printf("\t\t\t[1]:借书办理\t");printf(" [6]:还书办理\n");

printf("\n");

printf("\t\t\t[2]:查询图书\t");printf(" [7]:查询学生\n");

printf("\t\t\t[3]:添加图书\t");printf(" [8]:添加学生\n");

printf("\t\t\t[4]:删除图书\t");printf(" [9]:删除学生\n");

printf("\t\t\t[5]:遍历图书\t");printf("[10]:遍历学生\n\n");

printf("\t\t\t〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓\n\n");

printf("\t\t\t0:退出\n\n");

printf("请选择<0~10>:");

scanf("%d",&choice);

switch(choice){

case 0:

system("cls");

printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");

printf("\n谢谢您的使用!\n\n");

break;

case 1:

system("cls");

printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓〓〓〓\n\n");

printf("输入借出图书编号:\n");

scanf("%d",&id);

printf("输入借入学生学号:\n");

scanf("%d",&student_id);

Lent_Book(id,student_id,head_book,head_student);

break;

case 2:

system("cls");

printf("\n\t\t\t〓〓〓〓〓图书管理系统〓〓

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值