图书管理系统(C++版)课程设计作业

使用介绍

图书管理系统源码由两部分组成,第一部分book.h头文件,第二部分book.cpp源文件。复制代码时需注意将book.h文件的源码单独放在一个一个文件里,文件名必须为book.h。源码文件也需放在一个单独的.cpp文件里。

book.h头文件

#include<iostream>
#include<string>
#include<stdlib.h>
#include<conio.h>
using namespace std;

//会员类
class VIP
{
public:
	int vnum;	//会员号
	string name;	//会员姓名
	int num;		//图书编号
	string bookName;  //书名
	string author;	//作者
	string press;	//出版社
	VIP *next;    //指针
};

//图书结点类
class Node
{
public:
	int num;		//图书编号
	string bookName;  //书名
	string author;	//作者
	string press;	//出版社
	Node *next;		//指针
};
VIP vip[100];
Node book[100];

void add();	//增加图书函数
void Output(Node p);	//输出图书信息函数
int LookupBook();	//通过书名查找
void LookupAuthor();	//通过作者名查找
int LookupNum();		//通过编号查找
void LookupPress();	//通过出版社查找
void addVIP();		//增加会员函数
void OutputVIP(VIP s);		//输出会员信息函数
int LookupNumVIP();		//按编号查询会员
void LookupNameVIP();		//按会员姓名查找会员
void DeleteVIPbook();		//删除会员借书信息
void Delete();		//删除会员函数
void Query();		//根据会员编号查询借书信息
void Return();		//还书函数
void Borrow();		//图书借阅函数
void Index();		//首页
void BookInterface();		//图书管理界面
void VIPInterface();		//会员管理界面
void DeleteBook();	//删除图书函数
void LookupBookIn();	//图书查询页面
void LookupVIPIn();//会员查询页面

book.cpp源文件

#include"book.h"
	
int main()
{
	Index();   //首页函数
	return 0;
}

//增加图书函数
void add()
{
	for(int i=0;i<100;i++){
		if(book[i].num==0){
			cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入图书编号:";
			cin>>book[i].num;
			cout<<endl;
			cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入书名:";
			cin>>book[i].bookName;
			cout<<endl;
			cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入作者:";
			cin>>book[i].author;
			cout<<endl;
			cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入出版社:";
			cin>>book[i].press;
			cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"图书添加成功"<<"\n"<<endl;
			break;
		}
	}
	return;
}

//删除图书函数
void DeleteBook(){
	int b=LookupNum();
	book[b].author='\0';
	book[b].bookName='\0';
	book[b].num=0;
	book[b].press='\0';
	cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"图书删除成功"<<endl;
}

//输出图书信息函数
void Output(int b){
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"图书编号:"<<book[b].num<<"    书名:"<<book[b].bookName<<"    作者:"<<book[b].author<<"    出版社:"<<book[b].press<<"\n"<<endl;
}

//通过书名查找
int LookupBook(){
	int j=0;
	string bookname;
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入书名:";
	cin>>bookname;
	for(int i=0;i<100;i++){
		if(book[i].bookName==bookname){
			j=1;
			Output(i);
			return i;
		}
	}
	if(j==0){
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"没有该图书"<<"\n"<<endl;
	}
	return 1000;
}

//通过作者名查找
void LookupAuthor(){
	int j=0;
	string author;
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入作者姓名:";
	cin>>author;
	for(int i=0;i<100;i++){
		if(book[i].author==author){
			j=1;
			Output(i);
		}
	}
	if(j==0){
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"没有该图书"<<"\n"<<endl;
	}
}

//通过编号查找
int LookupNum(){
	int j=0;
	int num;
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入图书编号:";
	cin>>num;
	for(int i=0;i<100;i++){
		if(book[i].num==num){
			j=1;
			Output(i);
			return i;
		}
	}
	if(j==0){
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"没有该图书"<<"\n"<<endl;
	}
	return 1000;
}

//通过出版社查找
void LookupPress(){
	int j=0;
	string press;
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入图书出版社:";
	cin>>press;
	for(int i=0;i<100;i++){
		if(book[i].press==press){
			j=1;
			Output(i);
			break;
		}
	}
	if(j==0){
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"没有该图书"<<"\n"<<endl;
	}
}

//增加会员函数
void addVIP(){
	for(int i=0;i<100;i++){
		if(vip[i].vnum==0){
			cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入会员编号:";
			cin>>vip[i].vnum;
			cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入会员名:";
			cin>>vip[i].name;
			cout<<"\t"<<"\t"<<"\t"<<"\t"<<"会员添加成功"<<"\n"<<endl;
			break;
		}
	}
}

//输出会员信息函数
void OutputVIP(int s){
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"会员编号:"<<vip[s].vnum<<"    会员姓名:"<<vip[s].name<<"\n"<<endl;
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"图书编号:"<<vip[s].num<<"    书名:"<<vip[s].bookName<<"    作者:"<<vip[s].author<<"    出版社:"<<vip[s].press<<endl;
}
//按编号查询会员
int LookupNumVIP(){
	int j=0;
	int num;
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入会员编号:";
	cin>>num;
	for(int i=0;i<100;i++){
		if(vip[i].vnum==num){
			OutputVIP(i);
			j=1;
			return i;
		}
	}
	if(j==0){
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"没有该会员"<<"\n"<<endl;
	}
	return 1000;
}

//按会员姓名查找会员
void LookupNameVIP(){
	int j=0;
	string name;
	cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入会员姓名:";
	cin>>name;
	for(int i=0;i<100;i++){
		if(vip[i].name==name){
			j=1;
			OutputVIP(i);
			break;
		}
	}
	if(j==0){
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"没有该会员"<<"\n"<<endl;
	}
}

//删除会员借书信息
void DeleteVIPbook(){
	int s=LookupNumVIP();
	vip[s].author='\0';
	vip[s].bookName='\0';
	vip[s].num=0;
	vip[s].press='\0';
}

//删除会员函数
void Delete(){
	int s=LookupNumVIP();
	vip[s].name='\0';
	vip[s].vnum=0;
	vip[s].author='\0';
	vip[s].bookName='\0';
	vip[s].num=0;
	vip[s].press='\0';
	cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"会员删除成功"<<endl;
}

//根据会员编号查询借书信息
void Query(){
	LookupNumVIP();
}

//还书函数
void Return(){
		DeleteVIPbook();
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"图书归还成功"<<"\n"<<endl;
}

//图书借阅函数
void Borrow(){
	int b=LookupBook();
	int s=LookupNumVIP();
		vip[s].bookName=book[b].bookName;
		vip[s].author=book[b].author;
		vip[s].num=book[b].num;
		vip[s].press=book[b].press;
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"借书成功"<<"\n"<<endl;
}

//首页
void Index(){
	int i;
	system("cls");
	cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****           图书管理系统         ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
	      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、图书管理      2、会员管理  ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请选择:";
		  cin>>i;
		  switch(i){
			case 1:
				BookInterface();
				break;
			case 2:
				VIPInterface();
				break;
			default:
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入1或2"<<"\n"<<endl;
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				Index();
		  }
}

//图书管理界面
void BookInterface(){
	system("cls");
	int i;
	cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
	      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****          图书管理系统          ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、增加图书      2、查询图书  ****"<<endl;
	      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  3、图书借阅      4、图书归还  ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  5、删除图书      6、返回首页  ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请选择:";
		  cin>>i;
		  switch(i){
			case 1:
				add();	//增加图书函数
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				BookInterface();
				break;
			case 2:
				LookupBookIn();	//图书查询页面
				break;
			case 3:
				Borrow();		//图书借阅函数
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				BookInterface();
				break;
			case 4:
				Return();		//还书函数
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				BookInterface();
				break;
			case 5:
				DeleteBook();	//删除图书函数
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				BookInterface();
				break;
			case 6:
				Index();
			default:
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入对应编号"<<"\n"<<endl;
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				BookInterface();
		  }
}

//会员管理界面
void VIPInterface(){
	system("cls");
	int i;
	cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****           图书管理系统         ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、增加会员      2、查询会员  ****"<<endl;
	      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  3、借书信息      4、删除会员  ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****          5、返回首页           ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请选择:";
		  cin>>i;
		  switch(i){
			case 1:
				addVIP();		//增加会员函数
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				VIPInterface();
				break;
			case 2:
				LookupVIPIn();  //会员查询页面
				break;
			case 3:
				Query();		//根据会员编号查询借书信息
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				VIPInterface();
				break;
			case 4:
				Delete();		//删除会员函数
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				VIPInterface();
				break;
			case 5:
				Index();
				break;
			default:
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入对应编号"<<"\n"<<endl;
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				VIPInterface();
		  }
}

//图书查询页面
void LookupBookIn(){
	system("cls");
	int i;
	cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"**************************************************"<<endl;
	      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****               图书管理系统               ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"**************************************************"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  1、图书编号查询      2、书名查询        ****"<<endl;
	      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  3、图书作者查询      4、图书出版社查询  ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****  5、返回上一页        6、返回首页        ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                          ****"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"**************************************************"<<"\n"<<endl;
		  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请选择:";
		  cin>>i;
		  switch(i){
			case 1:
				LookupNum();	//通过编号查找
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				LookupBookIn();
				break;
			case 2:
				LookupBook();	//通过书名查找
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				LookupBookIn();
				break;
			case 3:
				LookupAuthor();	//通过作者名查找
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				LookupBookIn();
				break;
			case 4:
				LookupPress();	//通过出版社查找
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				LookupBookIn();
				break;
			case 5:
				BookInterface();	//图书管理界面
				break;
			case 6:
				Index();
				break;
			default:
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入对应编号"<<"\n"<<endl;
				cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
				system("pause");
				LookupBookIn();
		  }
}

//会员查询页面
void LookupVIPIn(){
		int i;
		system("cls");
		cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
		      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****           图书管理系统         ****"<<endl;
		      cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      1、通过编号查找会员       ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      2、通过姓名查找会员       ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      3、返回上一页             ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****                                ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****      4、返回首页               ****"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"****************************************"<<"\n"<<endl;
			  cout<<"\t"<<"\t"<<"\t"<<"\t"<<"请选择:";
			  cin>>i;
			   switch(i){
					case 1:
						LookupNumVIP();		//按编号查询会员
						cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
						system("pause");
						LookupVIPIn();
						break;
					case 2:
						LookupNameVIP();		//按会员姓名查找会员
						cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
						system("pause");
						LookupVIPIn();
						break;
					case 3:
						VIPInterface();	//会员管理界面
						break;
					case 4:
						Index();
						break;
					default:
						cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t"<<"请输入对应编号"<<"\n"<<endl;
						cout<<"\n"<<"\t"<<"\t"<<"\t"<<"\t";
						system("pause");
						LookupVIPIn();
		  }
}
  • 16
    点赞
  • 183
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值