⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libmanage.cpp

📁 c++做的图书管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	cout<<endl<<endl<<endl<<endl;
	cout<<"\t\t***************************************************"<<endl;
	cout<<"\t\t\t\t  图书馆管理系统"<<endl;
	cout<<"\t\t***************************************************"<<endl;
	cout<<endl<<endl;
	cout<<"\t\t\t\t\t v1.0"<<endl;
	cout<<"\t\t\t\t\t Designed by Chenyangyang"<<endl;
	cout<<endl<<endl<<endl<<endl<<endl<<endl<<endl;
	system("pause");
}
people* Login(peoplelist &p)
{
	
	char username[15];
	char password[15];
	int count = 1;
	while(count <= 3)
	{
		system("cls");
	cout<<endl<<endl<<endl<<endl;
	cout<<"\t\t\t\t用户名:";
	cin.getline(username,15);
	if(p.Searchpeople(username))
	{
		cout<<"\t\t\t\t密  码:";
		cin.getline(password,15);
		if(strcmp(password,(p.Searchpeople(username))->getpassword()) == 0)
		{
			return p.Searchpeople(username);
		}
		else
		{
			cout<<"\t\t\tpassword wrong!"<<endl;
			system("pause");
			count++;
			continue;
		}
	}
	else
	{
		cout<<"\t\t\tcan not find this user"<<endl;
		system("pause");
		count++;
		continue;
	}
	}
	exit(1);
}
people *AddNewPeople(peoplelist &plist)
{
	
	char username[15];
	char password[15];
	char confirmpassword[15];
	int position;
	
		system("cls");
		cout<<endl<<endl<<endl<<endl;
		cout<<"\t\t\t        请输入用户名:";
		cin.getline(username,15);
		cout<<endl<<"\t\t\t请输入密码(6-14位):";
		cin.getline(password,15);
		if(strlen(password)<6) 
		{
			cout<<"\t\t\t\t不能小于6位!"<<endl;
			system("pause");
			return 0;
		}
		cout<<endl<<"\t\t\t请再次输入密码:";
		cin.getline(confirmpassword,15);
		if(strcmp(password,confirmpassword) !=0)
		{
			cout<<"\t\t\t两次输入密码不相同!"<<endl;
			system("pause");
			return 0;
		}
		if(plist.getTotalNum() == 0)
			position = 1;
		else
		{
			cout<<endl<<"\t\t请输入用户类型(1-管理员,2-学生):";
			cin>>position;
			if(position!=1&&position!=2)
			{
				cout<<"\t\t\t\t无效输入!"<<endl;
				system("pause");
				return 0;
			}
		}
		people *p = new people();
		p->setusername(username);
		p->setpassword(password);
		p->setposition(position);
		plist.Addpeople(p);
		cout<<"\t\t\t\t输入成功!"<<endl;
		cout<<"\t\t\t你添加的用户信息:"<<endl;
		cout<<"\t\t\t         用户名:"<<plist.getHead()->getusername()<<endl;
		cout<<"\t\t\t         密  码:"<<plist.getHead()->getpassword()<<endl;
		cout<<"\t\t\t         类  型:";
		if(p->getposition() == 1)
			cout<<"管理员"<<endl;
		else
			cout<<"学生"<<endl;
		system("pause");
		return p;	
}
void showtip()
{
	cout<<setw(15)<<"ISBN"<<setw(15)<<"书名"<<setw(15)<<"作者"<<setw(15)<<"出版社"<<setw(15)<<"库存"<<endl;
}
Bookdata* ReturnBook(BookLib &blist,people *p)
{
char isbn[14];
system("cls");
cout<<"\t\t\t请输入您要还书的ISBN号:";

cin.getline(isbn,14);
Bookdata *bp = p->getHead()->SearchbyISBN(isbn);
if(!bp)
{
	cout<<"您没有借此本书!"<<endl;
	system("pause");
	return 0;
}
else
{
	p->getHead()->DeleteBook(isbn);
	p->setBorrowedNum(p->getBorrowedNum()-1);
	bp = blist.SearchbyISBN(isbn);
	bp->setQtyonhand(bp->getQtyonhand()+1);
	return bp;
}
}
void ShowBorrowed(people *p)
{
	system("cls");
	cout<<endl<<endl;
	cout<<endl<<"  **********************************借阅情况**********************************"<<endl<<endl;
	cout<<"\t\t\t\t    姓 名:"<<p->getusername()<<endl;
	cout<<"\t\t\t\t    类 型:学生"<<endl;
	cout<<"\t\t\t\t最大借阅量:"<<p->getMaxNum()<<"本"<<endl;
	cout<<"\t\t\t\t  借阅期限:"<<p->getLendOutTime()<<"天"<<endl;
	cout<<"\t\t\t\t  已借阅量:"<<p->getBorrowedNum()<<"本"<<endl;
	cout<<endl<<"  **********************************借阅详细**********************************"<<endl<<endl;
	p->getHead()->ShowBookswithDate();
	system("pause");

}
int ModifyPassword(people *p)
{
	char password[15];
	char confirmpassword[15];
	while(1)
	{
		system("cls");
		
		cout<<"\t\t\t请输入您的新密码:";
		cin.get(password,15);
		cin.get();
		if(strlen(password)<6)
		{
			cout<<"\t\t\t密码不能少于6位"<<endl;
			system("pause");
			break;
		}
		else
		{			
			cout<<"\t\t\t请再次输入您的新密码:";
			cin.getline(confirmpassword,15);
			//cin.get();
			if(strcmp(confirmpassword,password) != 0 )
			{
				cout<<"\t\t\t两次输入的密码不相同!"<<endl;
				system("pause");;
				break;
			}
			else
			{
				p->setpassword(password);
				cout<<"\t\t\t\t密码修改成功!"<<endl;
				system("pause");
				return 0;
			}
		}
	}
} 
void StudMenuShow()
{
	system("cls");
	cout<<endl<<endl<<endl;	
	cout<<endl;	
	cout<<"\t\t\t  ********学生用户主菜单********   "<<endl;
	cout<<"                                    "<<endl;
	cout<<"                                    "<<endl;
	cout<<"\t\t\t            1.借书                 "<<endl;
	cout<<"\t\t\t            2.还书                 "<<endl;
	cout<<"\t\t\t            3.查书                 "<<endl;
	cout<<"\t\t\t            4.借阅情况             "<<endl;
	cout<<"\t\t\t            5.修改密码             "<<endl;
	cout<<"\t\t\t          Esc.退出系统             "<<endl;
	cout<<"\t\t\t                                    "<<endl;
	cout<<"\t\t\t         请输入1-5之间的数          "<<endl;
	cout<<"\t\t\t              请选择:              "<<endl;	
	
}
int LookupBook(BookLib &lookp)
{   int choice;
while(1)
{
    system("cls");
	cout<<endl<<endl<<endl<<endl<<endl;
	cout<<"\t\t\t\t[1].按照ISBN查书"<<endl;
	cout<<"\t\t\t\t[2].按照作者查书"<<endl;
	cout<<"\t\t\t\t[3].按照书名查书"<<endl;
	cout<<"\t\t\t\tEsc.返回主菜单"<<endl;
    //Bookdata *p=new Bookdata();

				   choice = getch();

				   switch(choice)
				   { 
				   case 49:{
				      
				      system("cls");
					  cout<<endl<<endl<<endl<<endl<<endl;
					  cout<<"\t\t\t请输入要查询的ISBN:";
					  char isbn[14];
					  cin.getline(isbn,14);
			          if(lookp.SearchbyISBN (isbn))
					  {
						  ShowBook(lookp.SearchbyISBN (isbn));
						  system("pause");
					  }
					  else
					  {
						  system("cls");
						  cout<<endl<<endl<<endl<<endl<<endl;
						  cout<<"\t\t\t\t  查无此书!"<<endl;
						  system("pause");
					  }
					  return 0;
						  }
					 
				   case 50:{					  
					  system("cls");
					  cout<<endl<<endl<<endl<<endl<<endl;
					  cout<<"\t\t\t请输入作者:";
					  char author[15];
					  cin.getline(author,15);
					  lookp.SearchbyAuthor(author);
					  system("pause");
					  return 0;
						  }
				          
				   case 51:{
                      system("cls");
					  cout<<endl<<endl<<endl<<endl<<endl;
					  cout<<"\t\t\t请输入书名:";
					  char title[51];					  
					  cin.getline(title,51);
					  lookp.SearchbyTitle(title);
					  system("pause");
					  return 0;
						  }
				   case 27:{return 0;}
				   default:;
				   }
}				   
}
//添加书目
void AddNewBook(BookLib &addp)//有一个错误
{ char ISBN[14];
  char bookTitle[51];
  char Author[30];
  char Pub[30];	 
  int  qtyOnhand;  
  system("cls");
  cout<<endl<<endl<<endl<<endl;
        cout<<"\t\t\t  请输入书名:";
  cin.getline(bookTitle,51);
  cout<<endl<<"\t\t\t  请输入作者:";
  cin.getline(Author,30);
  cout<<endl<<"\t\t\t请输入出版社:";
  cin.getline(Pub,30);
  cout<<endl<<"\t\t\t请输入ISBN号:";
  cin.getline(ISBN,14);
  cout<<endl<<"\t\t\t请输入书本数:";
  cin>>qtyOnhand;
  cin.get();
  Bookdata *p=new Bookdata();
  p->setISBN (ISBN);
  p->setTitle (bookTitle);
  p->setAuthor(Author);
  p->setPub (Pub);
  p->setQtyonhand (qtyOnhand);
  addp.AddBook(p);
  system("cls");
  cout<<endl<<endl<<endl<<endl;
  cout<<"\t\t\t                输入成功!"<<endl<<endl;
  cout<<"\t\t\t你添加的书目信息:"<<endl;
  cout<<"\t\t\t            ISBN:"<<p->getISBN()<<endl;
  cout<<"\t\t\t            书名:"<<p->getTitle ()<<endl;
  cout<<"\t\t\t            作者:"<<p->getAuthor ()<<endl;
  cout<<"\t\t\t          出版社:"<<p->getPub ()<<endl;
  cout<<"\t\t\t          库存量:"<<p->getQtyonhand ()<<endl;
  system("pause");  
}
//删除书目
void DeleteOneBook(BookLib &deletep)
{ 
	char ISBN[14];
    system("cls");
	cout<<endl<<endl<<endl<<endl;

    cout<<"               请输入你要删除书的ISBN号:";
  cin.getline(ISBN,14);
  if(deletep.DeleteBook(ISBN))
    cout<<"                             删除成功!"<<endl;
  else
	cout<<"                             查无此书!"<<endl;
  system("pause");
}
Bookdata* BorrowBook(BookLib &blist,people *p)
{
	char isbn[14];
	Bookdata *bpoint;
	system("cls");
	cout<<endl<<endl<<endl<<endl;
	if(p->getBorrowedNum() == p->getMaxNum())
	{
		cout<<"\t\t\t您的借书数目已经达到最大值!"<<endl;
		system("pause");
		return 0;
	}
	cout<<"\t\t\t请输入你要借书的ISBN号:";
	cin.getline(isbn,14);
	bpoint = blist.SearchbyISBN(isbn);
	if(!bpoint)
	{
		cout<<"\t\t\t查无此书!"<<endl;
		system("pause");
		return 0;
	}
	if(!bpoint->getQtyonhand())
	{
		cout<<"\t\t\t无库存!"<<endl;
		system("pause");
		return 0;
	}
	else
	{
		Bookdata *pp = new Bookdata();
		pp->setAuthor(bpoint->getAuthor());
		pp->setISBN(bpoint->getISBN());
		pp->setPub(bpoint->getPub());
		pp->setTitle(bpoint->getTitle());
		pp->setLendTime(getDate());
		pp->setreturnTime(AddDate(p->getLendOutTime()));
		bpoint->setQtyonhand(bpoint->getQtyonhand() - 1);		
		(p->getHead())->AddBook(pp);
		p->setBorrowedNum(p->getBorrowedNum()+1);
		return pp;
	}
}
int DeleteOnePeople(BookLib &blist,peoplelist &plist)
{
	char username[15];
	system("cls");
	cout<<endl<<endl<<endl<<endl;
	cout<<"\t\t\t请输入您删除的用户名:";
	cin.getline(username,15);
	
	people *p = plist.Searchpeople(username);

	if(!p){
		system("cls");
		cout<<endl<<endl<<endl<<endl;
		cout<<"\t\t\t\t无此用户!"<<endl;
		system("pause");
		return 0;
	}
	if(p->getposition() == 1)
	{
		system("cls");
		cout<<endl<<endl<<endl<<endl;
		cout<<"\t\t\t\t您无权删除此用户!"<<endl;
		system("pause");
		return 0;
	}
	while(p->getBorrowedNum())
	{
		Bookdata *bp = blist.SearchbyISBN(p->getHead()->getHead()->getISBN());	
	    p->setBorrowedNum(p->getBorrowedNum()-1);
	    bp->setQtyonhand(bp->getQtyonhand()+1);
	    p->getHead()->DeleteBook(p->getHead()->getHead()->getISBN());
	}	
	plist.Deletepeople(username);
	system("cls");
		cout<<endl<<endl<<endl<<endl;
		cout<<"\t\t\t\t删除成功!"<<endl;
		system("pause");
		return 1;
}
int ShowLendout(BookLib &blist,peoplelist &plist)
{
	char isbn[14];
	system("cls");
	cout<<endl<<endl;
	cout<<"\t\t\t请输入要查询书的ISBN号:";
	cin.getline(isbn,14);
	if(!blist.SearchbyISBN(isbn))
	{
		system("cls");
		cout<<endl<<endl<<endl<<endl;
		cout<<"\t\t\t     书库中没有此书!"<<endl;
		system("pause");
		return 0;
	}
	people *p = plist.getHead();
	cout<<endl<<" **********************************借阅情况**********************************"<<endl<<endl;
	cout<<setw(14)<<"ISBN"<<setw(20)<<"书名"<<setw(10)<<"借阅用户"<<setw(12)<<"借出时间"<<setw(12)<<"到期时间"<<endl;
	while(p)
	{
		Bookdata * bp = p->getHead()->SearchbyISBN(isbn);
		if(bp)
		{
			cout<<setw(14)<<bp->getISBN()<<setw(20)<<bp->getTitle()<<setw(10)<<p->getusername()<<setw(12)<<bp->getLendTime()<<setw(12)<<bp->getreturnTime()<<endl;
			p = p->getNext();
		}
		else
		{
			p = p->getNext();
		}
	}
	system("pause");
	return 1;
}
int ManageBooks(BookLib &blist,peoplelist &plist)
{
	int choice;	
	while(1)
	{
		system("cls");
		cout<<endl<<endl<<endl<<"\t\t\t   *******书目管理模块*******"<<endl<<endl;
		cout<<"\t\t\t\t[1].添加书目"<<endl;
		cout<<"\t\t\t\t[2].删除书目"<<endl;
		cout<<"\t\t\t\t[3].查看书目借阅情况"<<endl;
		cout<<"\t\t\t\t[4].查找书目"<<endl;
		cout<<"\t\t\t\t[5].查看所有书目"<<endl;
		cout<<"\t\t\t\tEsc.返回主菜单"<<endl;
		choice = getch();
		switch(choice)
		{
		case 49:{AddNewBook(blist);break;}
		case 50:{DeleteOneBook(blist);break;}
		case 51:{ShowLendout(blist,plist);break;}
		case 52:{LookupBook(blist);break;}
		case 53:{blist.ShowAllBooks();break;}
		case 27:{return 0;}
		default:;
		}
	}
}
int ManageUsers(BookLib &blist,peoplelist &plist)
{
	int choice;	
	while(1)
	{
		system("cls");
		cout<<endl<<endl<<endl<<"\t\t\t   *******用户管理模块*******"<<endl<<endl;
		cout<<"\t\t\t\t[1].添加用户"<<endl;
		cout<<"\t\t\t\t[2].删除用户"<<endl;
		cout<<"\t\t\t\t[3].查看学生级用户"<<endl;
		cout<<"\t\t\t\t[4].查看管理员级用户"<<endl;
		cout<<"\t\t\t\tEsc.返回主菜单"<<endl;
		choice = getch();
		switch(choice)
		{
		case 49:{AddNewPeople(plist);break;}
		case 50:{DeleteOnePeople(blist,plist);break;}
		case 51:{plist.showpeoplelist(2);break;}
		case 52:{plist.showpeoplelist(1);break;}
		case 27:{return 0;}
		default:;
		}
	}
}
int DeleteSelf(peoplelist &plist,people *p)//注销自己的帐户
{
	int choice;
	while(1){
	system("cls");
	cout<<endl<<endl<<endl<<endl;
	cout<<"\t\t\t你真的要注销自己的帐户吗?"<<endl;
	cout<<"\t\t\t!注销后你将不能再次登录!"<<endl<<endl;
	cout<<"\t\t\t    确定[S]   返回[C]    "<<endl;
    choice = getch();
	
	switch(choice)
	{
	case 83:
	case 115:{plist.Deletepeople(p->getusername());return 1;}
	case 67:
	case 99:{return 0;}
	default:;
	}
	}
}
void AdminMenuShow()
{
	system("cls");
	cout<<endl<<endl<<endl;
	cout<<"\t\t         ********管理员用户菜单********   "<<endl;
	cout<<"                                    "<<endl;
	cout<<"                                    "<<endl;
	cout<<"\t\t                  1.书目管理             "<<endl;	
	cout<<"\t\t                  2.用户管理            "<<endl;
	cout<<"\t\t                  3.修改密码           "<<endl;
	cout<<"\t\t                  4.自我注销           "<<endl;
	cout<<"\t\t                ESC.退出系统             "<<endl;
	cout<<"                                         "<<endl;
	cout<<" \t\t              请输入1-4之间的数          "<<endl;
	cout<<"\t\t                   请选择:              "<<endl;		
}	
int AdminMenu(BookLib &blist,people *p,peoplelist &plist)
{
	int choice;	
	while(1)
	{
		AdminMenuShow();		
		choice = getch();		
		switch(choice)
		{
		case 49:{ManageBooks(blist,plist);break;}	
		case 50:{ManageUsers(blist,plist);break;}	
		case 51:{ModifyPassword(p);break;}
		case 52:{if(DeleteSelf(plist,p)) return 0;break;}
		case 27 :{return 0;}
		default:;
		}
	}
}
int StudMenu(BookLib &blist,people *p)
{
	int choice;	
	while(1)
	{		
		StudMenuShow();		
		choice = getch();		
		switch(choice)
		{
		case 49:{BorrowBook(blist,p);break;}
		case 50:{ReturnBook(blist,p);break;}
		case 51:{LookupBook(blist);break;}
		case 52:{ShowBorrowed(p);break;}		
		case 53:{ModifyPassword(p);break;}
		case 27 :{return 0;}
		default:;
		}		
	}
}

people* Init(peoplelist &plist)//初始化
{
	system("cls");
	cout<<endl<<endl<<endl<<endl;
	cout<<"\t\t\t 初次起动程序需要进行初始化"<<endl;
	cout<<"\t\t\t初始化之后您将成为该系统管理员"<<endl;
	system("pause");
	return AddNewPeople(plist);    
}
void main()
{
	system("color 5f");
	BeginShow();
	peoplelist plist;
	BookLib blist;	
	people *p;
    if(!plist.getTotalNum())
	{
		p = Init(plist);
		AdminMenu(blist,p,plist);
	}
	else
	{
		p = Login(plist);
		if(p->getposition() == 1)
		{
			AdminMenu(blist,p,plist);
		}		
		else
		{
			StudMenu(blist,p);
		}
	}
}
void BookLib::ShowAllBooks()
{
	Bookdata *p = head;
	system("cls");
	while(p)
	{
		if(p == head)
		{
			cout<<setw(15)<<"ISBN"<<setw(15)<<"书名"<<setw(15)<<"作者"<<setw(15)<<"出版社"<<setw(15)<<"库存"<<endl;
		}
		ShowBook(p);
		p = p->getNext();
	}
	system("pause");
}

void people::setLendOutTime(int n)
{
	LendOutTime = n;
}

int people::getLendOutTime()
{
	return LendOutTime;
}

void BookLib::ShowBookswithDate()
{
	Bookdata *p = head;
	while(p)
	{
		if(p == head)
		{
			cout<<setw(13)<<"ISBN"<<setw(16)<<"书名"<<setw(12)<<"作者"<<setw(14)<<"出版社"<<setw(11)<<"借出时间"<<setw(11)<<"到期时间"<<endl;
		}
		ShowBookDate(p);
		p = p->getNext();
	}
}

int peoplelist::getTotalNum()
{
	return TotalNum;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -