图书借阅管理系统(C++)数据结构课程设计

发布时间:2024-11-10

图书借阅管理系统(C++)数据结构课程设计

//姓名:吴华帅
//班级:信管092
//学号:3090703211、
/*图书借阅管理系统:
要求:为一个图书馆设计一个简单的借阅管理选题,主要分为两大功能:
图书管理(增加图书、查询图书、删除图书、图书借阅、还书);
会员管理(增加会员、查询会员、删除会员、借书信息);*/



#include "stdio.h"
#include "iostream.h"
#include "stdafx.h"
#include "malloc.h"
#include "stdlib.h"
#include <conio.h>
#include <string>

/*************************************结构体部分************************************/
/************图书信息结构体*************/
typedef struct elem
{
char bookid[5];
char bookname[20];
char bookauthor[50];
char bookmark[2];
char memberid[4];
}elemtype;
/************图书链表结点结构体*************/
typedef struct node
{
elemtype data;
struct node *next;
}lnode,*linknode;
/************会员信息结构体*************/
typedef struct memberelem
{
char memberid[4];
char membername[10];
}memberelemtype;
/************会员链表结点结构体*************/
typedef struct membernode
{
memberelemtype data;
struct membernode *next;
}mlnode,*mlinknode;

/*************************************创建函数部分************************************/
//^^^^^^^^^^^^^^^^^创建与销毁部分^^^^^^^^^^^^^^^^^^^^^^^^^^//
/************创建空图书链表*************/
linknode Init_lnode()
{
linknode head;
head=(linknode)malloc(sizeof(lnode));
if(head)
{
head->next=NULL;
head->data.bookauthor[50]=NULL;
head->data.bookid[5]=NULL;
head->data.bookmark[2]=NULL;
head->data.bookname[20]=NULL;
head->data.memberid[4]=NULL;
}
return head;
}
/************销毁图书链表*************/
void Destroy_lnode(linknode *head)
{
linknode p,q;
if (!(*head))
return;
p=*head;
while(!p)
{
q=p;
p=p->next;
free(q);
}
*head=NULL;
}
/************创建空会员链表*************/
mlinknode Init_mlnode()
{
mlinknode mhead;
mhead=(mlinknode)malloc(sizeof(mlnode));
if(mhead)
{
mhead->next=NULL;
mhead->data.memberid[4]=NULL;
mhead->data.membername[10]=NULL;
}
return mhead;
}
/************销毁会员链表*************/
void Destroy_mlnode(mlinknode *mhead)
{
mlinknode p,q;
p=*mhead;
if (!(*mhead))
return;
while(p)
{
q=p;
p=p->next;
free(q);
}
*mhead=NULL;
}
//^^^^^^^^^^^^^^^^^图书管理函数^^^^^^^^^^^^^^^^^^^^^^^^^^//
/************增加图书模块*************/
void addbook(linknode head)
{
linknode p;
p=(linknode)malloc(sizeof(lnode));
system("cls");
printf("Add books....\n");
printf("please input bookinfo:\n\n");
printf("%-7s%-20s%-15s\n","id(4)","bookname","bookauthor");
printf("**********************
******************************************\n");
//scanf("%s%s%s",p->data.bookid,p->data.bookname,p->data.bookauthor);

图书借阅管理系统(C++)数据结构课程设计

cin>>p->data.bookid;
cin>>p->data.bookname;
cin>>p->data.bookauthor;
p->data.bookmark[0]='N';
p->data.bookmark[1]='\0';
p->data.memberid[0]='0';
p->data.memberid[1]='\0';
p->next=head->next;
head->next=p;
printf("\n\nAdd success!\n");
printf("\nPress anykey retrun...");
getchar();
getchar();
}
/************输出图书信息函数*************/
void printbookinfo(linknode head)
{
linknode p;
p=Init_lnode();
p=head->next;
system("cls");
printf("The book informations are:\n\n");
cout<<"id \tbookname\tbookauthor\ttmark\tborower \t\n";
//printf("\t\n","\t\t\n","\t\t\n","\t\n""\t\n","id","bookname","bookauthor","mark","borower");
cout<<"****************************************************************"<<endl;
while(p)
{
cout<<p->data.bookid<<" \t";
cout<<p->data.bookname<<" \t \t";
cout<<p->data.bookauthor<<" \t \t";
cout<<p->data.bookmark<<" \t";
cout<<p->data.memberid<<endl;
p=p->next;
}
getchar();
}
/************按编号查询图书*************/
void select(linknode head)
{
char id[5];
linknode p;
system("cls");
p=head->next;
printf("select book by id.....\n\n");
printf("Please input book id:\n");
cin>>id;
while(p)
{
if(strcmp(p->data.bookid,id)==0) break;
else p=p->next;
}
if(p==NULL)
printf("\nThe book not exit!\n");
else
{
//printf("\t\n","\t\t\n","\t\t\n","\t\n""\t\n","id","bookname","bookauthor","mark","borower");
cout<<"id \tbookname\tbookauthor\ttmark\tborower \t\n";
//printf("\t\n","\t\t\n","\t\t\n","\t\n""\t\n","id","bookname","bookauthor","mark","borower");
cout<<"****************************************************************"<<endl;
printf("\n%-7s%-20s%-15s%-3s%s\n",p->data.bookid,p->data.bookname,p->data.bookauthor,p->data.bookmark,p->data.memberid);
}
printf("\nPress anykey retrun...");
getchar();
}
/************按编号删除图书*************/
void deletebook(linknode head)
{
char id[5];
linknode p,q;
system("cls");
p=head->next;q=head;
printf("delete book by id....\n\n");
printf("Please input book id:\n");
scanf("%s",id);
while(p!=NULL)
{
if(strcmp(p->data.bookid,id)==0) break;
else
{
q=p;p=p->next;
}
}
if(p==NULL) printf("\nThe book you want to delete are not exit!\n");
else
{
q->next=p->next;
free(p);
printf("\nDelete success!\n");
}
printf("\nPress anykey retrun...");
getchar();
getchar();
}
/****************借阅图书*****************/
void borrow(linknode head,mlinknode mhead)
{
char id[5];
char mid[4];
linknode p;
mlinknode q;
p=head;
q=mhead->next;
system("cls");
printf("borrow book....\n\n"
);
printf("Please input book id:\n");
cin>>id;
while(p)
{
if(p)
{
if(strcmp(p->data.bookid,id)!=0)
p=p->next;

图书借阅管理系统(C++)数据结构课程设计

else
break;
}

}
if(p==NULL){
printf("\nThe book doesn't exit! please input it again!\n\n");
getchar();
}
else//下面全体
{
printf("\nPlease input member id:\n");
cin>>mid;
while(q)
{
if(q)
{
if(strcmp(q->data.memberid,mid)!=0)
q=q->next;
else
break;
}

}
if(q==NULL){
printf("\nYou are not member! input again\n");

}
else{

if(((strcmp(p->data.bookmark,"Y"))!=0))
{
strcpy(p->data.bookmark,"Y");
strcpy(p->data.memberid,q->data.memberid);
printf("\nsuccessed!\n");
getchar();
}
else
{
printf("\n\nThe book have borrowed, please wait a few days...");
getchar();
}
}
}

printf("\n\nPress anykey retrun...");
getchar();
}
/****************还书****************/
void returnbook(linknode head)
{
char id[5];
linknode p;
system("cls");
p=head->next;
printf("return book....\n\n");
printf("Please input book id:\n");
cin>>id;
while(p!=NULL)
{
if(strcmp(p->data.bookid,id)==0) break;//strcmp为库文件,返回值为0时,两数相等
else p=p->next;
}
if(p==NULL)
cout<<"你想还的书不存在!"<<endl;
else
{
strcpy(p->data.bookmark,"N");
strcpy(p->data.memberid,"0");
cout<<"successed!"<<endl;
}
cout<<"Press anykey retrun..."<<endl;
getchar();
}
//^^^^^^^^^^^^^^^^^会员管理函数^^^^^^^^^^^^^^^^^^^^^^^^^^//
/************输出会员信息函数*************/
void printmemberinfo(mlinknode mhead)
{
mlinknode mp;
mp=Init_mlnode();
mp=mhead->next;
system("cls");
printf("The member infomations are....\n\n");
printf("%-7s%s\n","id","name");
printf("********************************************************\n\n");
for(;mp!=NULL;mp=mp->next)
printf("%-7s%s\n",mp->data.memberid,mp->data.membername);
printf("\nPress anykey retrun...");
getchar();
getchar();
}
/************增加会员模块*************/
void addmember(mlinknode mhead)
{
mlinknode p;
p=(mlinknode)malloc(sizeof(mlnode));
system("cls");
printf("Add member...\n");
printf("please input memberinfo:\n\n");
printf("%-7s%s\n","id(3)","name");
printf("********************************************************\n");
cin>>p->data.memberid>>p->data.membername;
p->next=mhead->next;
mhead->next=p;
printf("\n\nAdd success!");
printf("\nPress anykey retrun...");
getchar();
getchar();
}
/************按编号查询会员*************/
void selectmember(mlinknode mhead)
{
char id[4];
mlinknode p;
system("cls");
printf("select member by id...\n\n");
p=mhead->next;
printf("Please input member id:\n");
scanf("%s",id);
while(p!=NULL)
{
if(strcmp(p-&
gt;data.memberid,id)==0) break;
else p=p->next;
}
if(p==NULL) printf("\nThe member not exit!\n");
else
{
printf("\n%-

图书借阅管理系统(C++)数据结构课程设计

7s%s\n","id","name");
printf("********************************************************\n\n");
printf("%-7s%s\n",p->data.memberid,p->data.membername);
}
printf("\n\nPress anykey retrun...");
getchar();
getchar();
}
/************按编号删除会员*************/
void deletemember(mlinknode mhead)
{
char id[4];
mlinknode p,q;
system("cls");
printf("delete member......\n\n");
p=mhead->next;q=mhead;
printf("Please input member id:\n");
scanf("%s",id);
while(p!=NULL)
{
if(strcmp(p->data.memberid,id)==0) break;
else
{
q=p;p=p->next;
}
}
if(p==NULL) printf("\nThe member you want to delete are not exit!\n");
else
{
q->next=p->next;
free(p);
printf("\nDelete success!\n");
}
printf("\nPress anykey retrun...");
getchar();
getchar();

}
/************查询会员借书信息*************/
void selectmemberborrow(linknode head,mlinknode mhead)
{
char id[4];
mlinknode p;
linknode q;
system("cls");
printf("select member by id...\n\n");
p=mhead->next;
q=head->next;
printf("Please input member id:\n");
cin>>id;
while(p!=NULL)
{
if(strcmp(p->data.memberid,id)==0) break;
else
p=p->next;
}
if(p==NULL)
printf("\nThe member not exit!\n");
else
{
while(q)
{
if(strcmp(q->data.memberid,id)==0) break;
else q=q->next;
}
if(q==NULL)
printf("\nThe member not borrow book!\n");
else
{
cout<<"bookid\tbookname\tmember"<<endl;
printf("********************************************************\n\n");
cout<<q->data.bookid<<"\t"<<q->data.bookname<<"\t"<<p->data.membername<<endl;
}
}
printf("\n\nPress anykey retrun...");
getchar();
getchar();
}
//^^^^^^^^^^^^^^^^^二级管理函数与主函数^^^^^^^^^^^^^^^^^^^^^^^^^^//
/************二级图书管理目录*************/
void bookmanagetitle()
{
system("cls");
printf(" BOOK MANAGE MENU \n");
printf("******************************************\n");
printf("* 1: Look all books 查看所有图书 *\n");
printf("*----------------------------------------*\n");
printf("* 2: Add book 增加图书 *\n");
printf("*----------------------------------------*\n");
printf("* 3: Select book by id 查询图书 *\n");
printf("*----------------------------------------*\n");
printf("* 4: Delete book by id 删除图书 *\n");
printf("*----------------------------------------*\n");
printf("* 5: Borrow book 借阅图书 *\n");
printf("*----------------------------------------*\n");
printf("* 6: Return book 归还图书 *\n");
printf("*--------------------------------------
--*\n");
printf("* 0: Return to main form 返回主界面 *\n");
printf("******************************************\n");

图书借阅管理系统(C++)数据结构课程设计

printf("\nPlease input order:\n");
}
/************二级图书管理函数*************/
void bookmanage(linknode head,mlinknode mhead)
{
int ch;
while(1)
{
bookmanagetitle();
//scanf("%d",&ch);
cin>>ch;
if(ch==0) break;
switch(ch)
{
case 1: printbookinfo(head);break;
case 2: addbook(head);break;
case 3: select(head);break;
case 4: deletebook(head);break;
case 5: borrow(head,mhead);break;
case 6: returnbook(head);break;
case 0:break;
default: printf("\n\nYou hava input the wrong order!\n");
printf("Press anykey return.....");getchar();getchar();
}
}
}
/************二级会员管理目录*************/
void membermanagetitle()
{
system("cls");
printf(" MEMBER MANAGE MENU \n");
printf("******************************************\n");
printf("* 1: Look all memberinfo 查看所有会员 *\n");
printf("*----------------------------------------*\n");
printf("* 2: Add member 增加会员 *\n");
printf("*----------------------------------------*\n");
printf("* 3: Select member by id 查询会员 *\n");
printf("*----------------------------------------*\n");
printf("* 4: Delete member by id 删除会员 *\n");
printf("*----------------------------------------*\n");
printf("* 5: select member borrow借书信息 *\n");
printf("*----------------------------------------*\n");
printf("* 0: Return to main form 返回主菜单 *\n");
printf("******************************************\n");
printf("\nPlease input order:\n");
}
/************二级会员管理函数*************/
void membermanage(linknode head,mlinknode mhead)
{
int ch;
while(1)
{
membermanagetitle();
cin>>ch;
if(ch==0) break;
switch(ch)
{
case 1:
printmemberinfo(mhead);
break;
case 2:
addmember(mhead);
break;
case 3:
selectmember(mhead);
break;
case 4:
deletemember(mhead);
break;
case 5:
selectmemberborrow(head,mhead);
break;
case 0:
break;
default:
printf("\nYou hava input the wrong order!\n");
printf("Press anykey return.....");getchar();getchar();
}
}
}
/************系统总菜单*************/
void welform()
{
system("cls");
system("color fd");
cout<<"\n\t\t\t★ 欢 ";
cout<<"★ 迎 ";
cout<<"★ 进 ";
cout<<"★ 入 ";
cout<<"★"<<endl;
system("DATE[/T]");
system("TIME[/T]");
cout<<"\t ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n";
cout<<"\t ☆ ☆\n";
cout<<"\t
☆ 图 书 借 阅 管 理 系 统 ☆\n";
cout<<"\t ☆ ☆\n";

图书借阅管理系统(C++)数据结构课程设计

cout<<"\t ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n";
cout<<("\t\t* 1: book manage 图书管理 *\n");
cout<<("\t\t*---------------------------------------*\n");
cout<<("\t\t* 2: member manage 会员管理 *\n");
cout<<("\t\t*---------------------------------------*\n");
cout<<("\t\t* 0: quit 退出 *\n");
cout<<("\t\t*****************************************\n");
cout<<("\n\nPlease input order:\n");
}

/************主函数*************/
void main()
{
linknode head;
mlinknode mhead;
head=Init_lnode();
mhead=Init_mlnode();
int ch;
while(1)
{
welform(); /*系统总菜单*/
cin>>ch;
switch(ch)
{
case 1:
bookmanage(head,mhead); /*二级图书管理功能选择函数*/
break;
case 2:
membermanage(head,mhead); /*二级会员管理功能选择函数*/
break;
case 0:
exit(0); /*退出系统*/
default:
printf("\nYou hava inpu
t the wrong order!\n");
printf("Press anykey return.....");
}
}
Destroy_lnode(&head);
Destroy_mlnode(&mhead);
}


图书借阅管理系统(C++)数据结构课程设计.doc 将本文的Word文档下载到电脑

    精彩图片

    热门精选

    大家正在看

    × 游客快捷下载通道(下载后可以自由复制和排版)

    限时特价:7 元/份 原价:20元

    支付方式:

    开通VIP包月会员 特价:29元/月

    注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
    微信:fanwen365 QQ:370150219