之前参照网上的资料用链表实现了图书管理系统,包括简单的增删改查功能以及借书还书功能,我是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,