第八章 第一个“系统”——图书管理系统

时间:2022-10-25 17:48:31

本来是想一直就这样做做题,想想算法,思考思考,然后找些有代表性的,作为《程序员之路》的一章,但是写了前面七章,总觉得如果再这样下去,《程序员之路》最多也只是自己写代码时的一本参考书,别人学算法的一本资料书,体现不出这大学四年来我自己个人究竟做了些什么,什么才是这四年来最值得回味的东西。还有就是如果只是算法的话,我也只是将别人的代码学习、借鉴、多参考、总结、甚至有时直接拷贝得来,显得毫无意义,所以,我决定从这章开始真正跨入到我的大学(但是,写算法、学算法数据结构是每个程序员的必经之路,前七章就作为前期准备工作吧)

这刚开始的一章就先从我大一刚步入程序员这条路时说起吧。翻开以前写的程序,大一时写的就只剩下这个程序了,保留下来的原因只是因为代码量“非常大”,总计1674行,现在看起来显得很微不足道,但当时作为大一的一份子,1674多是一个可能卖弄的数据啊,虽然说代码质量不怎么样,但就是这个行数也足够我虚荣半年的了。
记得当时这是道老师布置的附加题,写的最好的那个平时分可以多10分(总分也就是多1分,不过一般情况下,平时分都在90分以上,再怎么加都不会超过100吧,所以现在想想都是噱头),其实当时压根没想着加分的事情,因为其他考试不说,单就c和c++两场考试我还是有绝对信心考高分的,只能说是虚荣心作祟,我花了整整一个星期来做这件事,其实最后的版本有3000多行代码,加入了n多功能,但是由于当时备份不充分,电脑维修删掉了,只剩下这个2天版的,1674行,功能还算齐全。
代码比较简单,先介绍下主要功能,然后贴下代码
1、刚开始页面如下,还挺花哨
第八章 第一个“系统”——图书管理系统
2、进入后,看看选项其实就知道实现什么功能了,这里只提供了管理员功能,根据借阅者身份的不同,借书时间不同,这是超期读者和图书的处理
第八章 第一个“系统”——图书管理系统
3、再贴一张借书界面:
第八章 第一个“系统”——图书管理系统
根据以上三张图,也就完全了解其功能了,代码附上:
// f.cpp : 定义控制台应用程序的入口点。
//

// tu1.cpp : 定义控制台应用程序的入口点。
//
#include <iostream>
using namespace std;
#include <iomanip>
#include <string>
#include <fstream>              
#include <time.h>

#define Barcode 20
#define Name 20
#define Author 20
#define Publish 20
#define PublishTime 20
#define ISBN 20
#define Maxbook 100                 
#define Maxperson 100               

#define PersonName 20

#define StudentName 20



 //声明//
int main_interface();    //主界面
int welcome_interface1();
void leave_interface();

char judge();                               
int interface1();
int interface2();
void count(int days,int &year,int &month,int &day);
void getSystemTime(int &year,int &month,int &day);
int timejudge(int year,int month,int day);//到期的年月日  返回是否超期   0超期  1  未超期
//声明//


//类
class Book
{
private:
    bool del;                        
	bool if_borrow;                        

	int num;                        
	char barcode[Barcode];           
	char name[Name];              
	char author[Author];                
	char publish[Publish];
	char publish_time[PublishTime];
	char isbn[ISBN];

public:
	Book(){}
	char getbarcode()                  //获取图书类型
	{
		return barcode[Barcode];
	}                                
	char getname()	                //获取书名
	{
		return name[Name]; 
	}
	char getauthor()
	{
		return author[Author];
	}
	char getpublish()
	{
		return publish[Publish];
	}
	char getpublish_time()
	{
		return publish_time[PublishTime];
    }
	char getisbn()
	{
		return isbn[ISBN];
	}
	int getnum()                     //获取图书编号
	{
		return num; 
	}

	bool get_del()                    //获取删除标记
	{
		return del;
	}
	bool get_if_borrow()
	{
		return if_borrow;
	}

	void setif_borrow(bool if_b)
	{
		if_borrow=if_b;
	}
	void setbarcode(char ba[])         //设置书名
	{
		strcpy(barcode,ba);
	}
	void setname(char na[])         //设置书名
	{
		strcpy(name,na);
	}
	void setauthor(char au[])         //设置书名
	{
		strcpy(author,au);
	}
	void setpublish(char pu[])         //设置书名
	{
		strcpy(publish,pu);
	}
	void setpublish_time(char pl[])         //设置书名
	{
		strcpy(publish_time,pl);
	}
	void setisbn(char is[])         //设置书名
	{
		strcpy(isbn,is);
	}

	void del_book()                  //删除图书
	{
		del=true;
	}

	void add_book(int n,char *ba,char *na,char *au,char *pu,char *pl,char *is)    //增加图书
	{
		del=false;
		num=n;
		strcpy(barcode,ba);
		strcpy(name,na);
		strcpy(author,au);
		strcpy(publish,pu);
		strcpy(publish_time,pl);
		strcpy(isbn,is);
	}
	
	void display()                     //输出图书
	{
		cout<<setw(5)<<num<<setw(10)<<barcode<<setw(10)<<name<<setw(10)<<author<<setw(10)<<publish<<setw(10)<<publish_time<<setw(10)<<isbn<<setw(10);		
		if(if_borrow==true)cout<<"已借"<<endl;
		else cout<<"未借"<<endl;
	}
};


class Student
{
protected:
	bool del;
	int tip;
	char student_name[StudentName];
	float student_number;
	int book_number[10];
	int book_year[10],book_turnyear[10];
	int book_month[10],book_turnmonth[10];
	int book_day[10],book_turnday[10];
public:
	Student()
	{
		tip=-1;
		int i;
		for(i=0;i<=9;i++)
		{
		book_number[i]=0;
		book_year[i]=0;
		book_month[i]=0;
		book_day[i]=0;
		}
	}
	void del_student()                  //删除图书
	{
		del=true;
	}

	bool get_del()                    //获取删除标记
	{
		return del;
	}

     char getstudent_name()
	{
		return student_name[StudentName];
	}

     float getstudent_number()
	{
		return student_number;
	}
	 
	 int getbook_number(int n)
	 {
		 return book_number[n];
	 }

	 int getbook_turnyear(int n)
	 {
		 return book_turnyear[n];
	 }
	 int getbook_turnmonth(int n)
	 {
		 return book_turnmonth[n];
	 }
	 int getbook_turnday(int n)
	 {
		 return book_turnday[n];
	 }

	 int gettip()
	 {
		 return tip;
	 }

	 void book_back()
	 {
		 tip--;
	 }

	void setstudent_name(char *sn)
	{
		strcpy(student_name,sn);
	}

	void setstudent_number(float number)
	{
		student_number=number;
	}

	void setbook_number(int n,int number)
	{
		book_number[n]=number;
	}

	void settle(char *sn,float number)
	{
		strcpy(student_name,sn);
		student_number=number;
	}

	void show()
	{
		cout.flags (ios::left);     //设置对齐的标志位为左

		for(int i=0;i<=tip;i++)
		{		
			cout<<setw(15)<<Student::student_name<<setw(10)<<Student::student_number;
			cout<<setw(5)<<book_number[i];
			cout<<setw(5)<<book_year[i]<<"年"<<book_month[i]<<"月"<<book_day[i]<<"日    ";
			cout<<setw(5)<<book_turnyear[i]<<"年"<<book_turnmonth[i]<<"月"<<book_turnday[i]<<"日"<<endl;
		}
	}
	void showone(int i)
	{
		cout.flags (ios::left);     //设置对齐的标志位为左
		    cout<<setw(15)<<Student::student_name<<setw(10)<<Student::student_number;
			cout<<setw(5)<<book_number[i];
			cout<<setw(5)<<book_year[i]<<"年"<<book_month[i]<<"月"<<book_day[i]<<"日    ";
			cout<<setw(5)<<book_turnyear[i]<<"年"<<book_turnmonth[i]<<"月"<<book_turnday[i]<<"日"<<endl;
	}
};
class Undergraduate : public Student
{
private:
	int tg;
public:
	Undergraduate()
	{
		tg=4;
	}
	int gettg()
	{
		return tg;
	}
	float getstudent_number()
	{
		return Student::student_number;
	}
	void borrow(char *sn,float number,int num,int year,int month,int day)
	{
		del=false;

		tip++;
		strcpy(student_name,sn);
		student_number=number;
		book_number[tip]=num;
		book_year[tip]=book_turnyear[tip]=year;
		book_month[tip]=book_turnmonth[tip]=month;
		book_day[tip]=book_turnday[tip]=day;
		count(60,book_turnyear[tip],book_turnmonth[tip],book_turnday[tip]);
	}
	
};
class Master : public Student
{
private:
	int tg;
public:
	Master()
	{
		tg=8;
	}
	int gettg()
	{
		return tg;
	}
	float getstudent_number()
	{
		return Student::student_number;
	}
	void borrow(char *sn,float number,int num,int year,int month,int day)
	{
		del=false;
		tip++;
		strcpy(student_name,sn);
		student_number=number;
		book_number[tip]=num;
		book_year[tip]=book_turnyear[tip]=year;
		book_month[tip]=book_turnmonth[tip]=month;
		book_day[tip]=book_turnday[tip]=day;
		count(90,book_turnyear[tip],book_turnmonth[tip],book_turnday[tip]);
	}
	
};
class Doctor : public Student
{
private:
	int tg;
public:
	Doctor()
	{
		tg=10;
	}
	int gettg()
	{
		return tg;
	}
	float getstudent_number()
	{
		return Student::student_number;
	}
	void borrow(char *sn,float number,int num,int year,int month,int day)
	{
		del=false;
		tip++;
		strcpy(student_name,sn);
		student_number=number;
		book_number[tip]=num;
		book_year[tip]=book_turnyear[tip]=year;
		book_month[tip]=book_turnmonth[tip]=month;
		book_day[tip]=book_turnday[tip]=day;
		count(120,book_turnyear[tip],book_turnmonth[tip],book_turnday[tip]);
	}
	
};
class Teacher : public Student
{
private:
	int tg;
public:
	Teacher()
	{
		tg=10;
	}
	int gettg()
	{
		return tg;
	}
	float getstudent_number()
	{
		return Student::student_number;
	}
	void borrow(char *sn,float number,int num,int year,int month,int day)
	{
		del=false;
		tip++;
		strcpy(student_name,sn);
		student_number=number;
		book_number[tip]=num;
		book_year[tip]=book_turnyear[tip]=year;
		book_month[tip]=book_turnmonth[tip]=month;
		book_day[tip]=book_turnday[tip]=day;
		count(120,book_turnyear[tip],book_turnmonth[tip],book_turnday[tip]);
	}
	
};


class Bdeal
{
private:
    int top;                        
	Book book[Maxbook];                

	int topu,topm,topd,topt;

	Undergraduate ug[Maxperson];
	Master mr[Maxperson];
	Doctor dr[Maxperson];
	Teacher tr[Maxperson];

public:
	Bdeal()                     //构造函数
	{ 
			Book b;
			Undergraduate u;
			Master m;
			Doctor d;
			Teacher t;

			top=topu=topm=topd=topt=-1;

			ifstream fout("c:\\book.txt");
			ifstream foutu("c:\\undergraduate.txt");
			ifstream foutm("c:\\master.txt");
			ifstream foutd("c:\\doctor.txt");
			ifstream foutt("c:\\teacher.txt");
			while (1)
			{
				fout.read((char *)&b,sizeof(b));
				if (!fout) break;
				top++;
				book[top]=b;
			}
			fout.close();
			while (1)
			{
				foutu.read((char *)&u,sizeof(u));
				if (!foutu) break;
				topu++;
				ug[topu]=u;
			}
			foutu.close();
			while (1)
			{
				foutm.read((char *)&m,sizeof(m));
				if (!foutm) break;
				topm++;
				mr[topm]=m;
			}
			foutm.close();
			while (1)
			{
				foutd.read((char *)&d,sizeof(d));
				if (!foutd) break;
				topd++;
				dr[topd]=d;
			}
			foutd.close();
			while (1)
			{
				foutt.read((char *)&t,sizeof(t));
				if (!foutt) break;
				topt++;
				tr[topt]=t;
			}
			foutt.close();
	} 

	void clear()                    
	{
		top=-1;
	}
	void clearu()                    
	{
		topu=-1;
	}
	void clearm()                   
	{
		topm=-1;
	}
	void cleard()                    
	{
		topd=-1;
	}
	void cleart()                    
	{
		topt=-1;
	}


    int addbook(int n,char *ba,char *na,char *au,char *pu,char *pl,char *is)     
	{
		Book *p=query(n);
		if(NULL==p)
		{
			top++;
			book[top].add_book(n,ba,na,au,pu,pl,is);
			return 1;
		}
		return 0;
	}
	int add_u(char *name,float number,int num)
	{
		int year,month,day;
		Undergraduate *p=queryu(number);
		if(NULL==p)
		{
			topu++;
			
			getSystemTime(year,month,day);
			ug[topu].borrow(name,number,num,year,month,day);
			Book *p=query(num);
			p->setif_borrow(true);
			return 1;
		}
		return 0;
	}

	int add_m(char *name,float number,int num)
	{
		int year,month,day;
		Master *p=querym(number);
		if(NULL==p)
		{
			topm++;
			getSystemTime(year,month,day);
			mr[topm].borrow(name,number,num,year,month,day);
			Book *p=query(num);
			p->setif_borrow(true);
			return 1;
		}
		return 0;
	}

	int add_d(char *name,float number,int num)
	{
		int year,month,day;
		Doctor *p=queryd(number);
		if(NULL==p)
		{
			topd++;
			getSystemTime(year,month,day);
			dr[topd].borrow(name,number,num,year,month,day);
			Book *p=query(num);
			p->setif_borrow(true);
			return 1;
		}
		return 0;
	}

	int add_t(char *name,float number,int num)
	{
		int year,month,day;
		Teacher *p=queryt(number);
		if(NULL==p)
		{
			topt++;
			getSystemTime(year,month,day);
			tr[topt].borrow(name,number,num,year,month,day);
			Book *p=query(num);
			p->setif_borrow(true);
			return 1;
		}
		return 0;
	}

	Book *query(int bookid)         //查找图书
	{
		for (int i=0;i<=top;i++)
			if (book[i].getnum()==bookid &&book[i].get_del()==false)
			{	
				return &book[i];
			}
			return NULL;
	}
	Book *query_left(int bookid)         
	{
		for (int i=0;i<=top;i++)
			if (book[i].getnum()==bookid &&book[i].get_del()==false&&book[i].get_if_borrow()!=true)
			{	
				return &book[i];
			}
			return NULL;
	}
	Book *query_out(int bookid)         
	{
		for (int i=0;i<=top;i++)
			if (book[i].getnum()==bookid &&book[i].get_del()==false&&book[i].get_if_borrow()==true)
			{	
				return &book[i];
			}
			return NULL;
	}

	Undergraduate *queryu(float snum)        
	{
		for (int i=0;i<=topu;i++)
			if (ug[i].getstudent_number()==snum&&ug[i].get_del()==false)
			{
				return &ug[i];
			}
			return NULL;
	}
	Master *querym(float snum)        
	{
		for (int i=0;i<=topm;i++)
			if (mr[i].getstudent_number()==snum&&mr[i].get_del()==false)
			{
				return &mr[i];
			}
			return NULL;
	}
	Doctor *queryd(float snum)         
	{
		for (int i=0;i<=topd;i++)
			if (dr[i].getstudent_number()==snum&&dr[i].get_del()==false)
			{
				return &dr[i];
			}
			return NULL;
	}
	Teacher *queryt(float snum)        
	{
		for (int i=0;i<=topt;i++)
			if (tr[i].getstudent_number()==snum&&tr[i].get_del()==false)
			{
				return &tr[i];
			}
			return NULL;
	}

	void handle();            

	void disp()
	{
	  for (int i=0;i<=top;i++)
		  if (book[i].get_del()==false)
			  book[i].display();
	}

	void dispout()
	{
		for (int i=0;i<=top;i++)
		  if (book[i].get_del()==false&&book[i].get_if_borrow()==true)
			  book[i].display();
	}

	void displeft()
	{
		for (int i=0;i<=top;i++)
		  if (book[i].get_del()==false&&book[i].get_if_borrow()!=true)
			  book[i].display();
	}

	void dispu()
	{
		for (int i=0;i<=topu;i++)
		  if (ug[i].get_del()==false)
			  ug[i].show();
	}
	void dispm()
	{
		for (int i=0;i<=topm;i++)
		  if (mr[i].get_del()==false)
			  mr[i].show();
	}
	void dispd()
	{
		for (int i=0;i<=topd;i++)
		  if (dr[i].get_del()==false)
			  dr[i].show();
	}
	void dispt()
	{
		for (int i=0;i<=topt;i++)
		  if (tr[i].get_del()==false)
			  tr[i].show();
	}

	~Bdeal()                    //析构函数
	{
		ofstream fin("c:\\book.txt");
		ofstream finu("c:\\undergraduate.txt");
	    ofstream finm("c:\\master.txt");
		ofstream find("c:\\doctor.txt");
		ofstream fint("c:\\teacher.txt");
        for (int i=0;i<=top;i++)
			if (book[i].get_del()==false)
				fin.write((char *)&book[i],sizeof(book[i]));
			fin.close();
		for (int i=0;i<=topu;i++)
			if (ug[i].get_del()==false)
				finu.write((char *)&ug[i],sizeof(ug[i]));
			finu.close();
		for (int i=0;i<=topm;i++)
			if (mr[i].get_del()==false)
				finm.write((char *)&mr[i],sizeof(mr[i]));
			finm.close();
		for (int i=0;i<=topd;i++)
			if (dr[i].get_del()==false)
				find.write((char *)&dr[i],sizeof(dr[i]));
			find.close();
		for (int i=0;i<=topt;i++)
			if (tr[i].get_del()==false)
				fint.write((char *)&tr[i],sizeof(tr[i]));
			fint.close();
	}

};


void Bdeal::handle()
{
    int choice=1;
	 int num;                        //
	char barcode[Barcode];            //
	char name[Name];              //
	char author[Author];                //
	char publish[Publish];
	char publish_time[PublishTime];
	char isbn[ISBN];

	

	Book *b;
	Undergraduate *u;
	Master *m;
	Doctor *d;
	Teacher *t;

	
    float snum;

	while (choice!=0)
	{   
	      choice=main_interface();
		switch (choice)
		{
            case 1:
				system("CLS");
				cout<<"输入图书编号:"<<endl;
				cin>>num;
				cout<<"输入图书条码:"<<endl;
				cin>>barcode;
				cout<<"输入图书名:"<<endl;
				cin>>name;
                cout<<"输入作者名:"<<endl;
				cin>>author;
				cout<<"输入出版社:"<<endl;
				cin>>publish;
				cout<<"输入出版时间:"<<endl;
				cin>>publish_time;
				cout<<"输入ISBN号:"<<endl;
				cin>>isbn;
				addbook(num,barcode,name,author,publish,publish_time,isbn);
				system("CLS");
				break;
           
			case 2:
				system("CLS");
				int n;
				while(1)
				{
				     n=interface2();
					if (n==0) 
						{
							system("CLS");
							break;
					    }
					else
					{
						system("CLS");
							cout<<"图书编号  图书条码    图书名    作者     出版社    出版时间   ISBN号 是否借出 \n";
							displeft();
							cout<<endl<<endl;
							cout<<"            输入图书编号"<<endl;
							cin>>num;
							b=query_left(num);
							 if (b==NULL)
						{
							cout<<"                 该图书不存在"<<endl;
							system("PAUSE");
							break;
						}
                            char name[PersonName];

							cout<<"          输入姓名"<<endl;
							cin>>name;
							cout<<"         输入学号:"<<endl;
							cin>>snum;
							
					if(n==1)
					{
						if(queryu(snum)!=NULL)
						{
						if(ug[topu].gettip()>=ug[topu].gettg()-1)
						{
							cout<<"                            你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
						break;
						}
						else
						{
							 int year,month,day;
							 getSystemTime(year,month,day);
							 ug[topu].borrow(name,snum,num,year,month,day);
							 b=query(num);
			                 b->setif_borrow(true);
						}
						}
						else 
						{
			                add_u(name,snum,num);
						}
					}
					 else if(n==2)
					{
						if(querym(snum)!=NULL)
						{
						if(mr[topm].gettip()>=mr[topm].gettg()-1)
						{
							cout<<"                        你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
						break;
						}
						else 
						{
							 int year,month,day;
							 getSystemTime(year,month,day);
				
							 mr[topm].borrow(name,snum,num,year,month,day);
							 b=query(num);
			                 b->setif_borrow(true);
						}
						}
						else
						{
				
			                add_m(name,snum,num);
						}
					}
					else if(n==3)
					{
						if(queryd(snum)!=NULL)
						{
						if(dr[topd].gettip()>=dr[topd].gettg()-1)
						{
							cout<<"                       你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
						break;
						}
						else 
						{
							 int year,month,day;
							 getSystemTime(year,month,day);
						
							 dr[topd].borrow(name,snum,num,year,month,day);
							 b=query(num);
			                 b->setif_borrow(true);
						}
						}
						else
						{
					
			                add_d(name,snum,num);
						}
					}
					else if(n==4)
					{
						if(queryt(snum)!=NULL)
						{
						if(tr[topt].gettip()>=tr[topt].gettg()-1)
						{
							cout<<"                       你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
						break;
						}
						else 
						{
							 int year,month,day;
							 getSystemTime(year,month,day);
					
							 tr[topt].borrow(name,snum,num,year,month,day);
							 b=query(num);
			                 b->setif_borrow(true);
						}
						}
						else
						{
			                add_t(name,snum,num);
						}
					}
					
					char tg;
					while(1)
					{
					cout<<"              是否继续借书:"<<endl;
					    tg=judge();
						if(tg=='n'||tg=='N')break;
						
						if(n==1&&ug[topu].gettip()>=ug[topu].gettg()-1)
						{
							cout<<"                你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
							system("CLS");
						break;
						}
						else if(n==2&&mr[topm].gettip()>=mr[topm].gettg()-1)
						{
							cout<<"               你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
							system("CLS");
						break;
						}
						else if(n==3&&dr[topd].gettip()>=dr[topd].gettg()-1)
						{
							cout<<"               你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
							system("CLS");
						break;
						}
						else if(n==4&&tr[topt].gettip()>=tr[topt].gettg()-1)
						{
							cout<<"                 你借的书已超过限额,不能再借"<<endl;
							system("PAUSE");
							system("CLS");
						break;
						}
						if(tg!='n'&&tg!='N')
					    {
							cout<<"                   输入图书编号"<<endl;
							cin>>num;
							b=query_left(num);
							 if (b==NULL)
						{
							cout<<"                  该图书不存在或是你已借过"<<endl;
							system("PAUSE");
							system("CLS");
							break;
						}
							 
							 int year,month,day;
							 getSystemTime(year,month,day);
							 if(n==1)ug[topu].borrow(name,snum,num,year,month,day);
							 if(n==2)mr[topm].borrow(name,snum,num,year,month,day);
							 if(n==3)dr[topd].borrow(name,snum,num,year,month,day);
							 if(n==4)tr[topt].borrow(name,snum,num,year,month,day);
							  b=query(num);
			                 b->setif_borrow(true);
						}
					}
					}
					system("CLS");
					break;
				
			}
			system("CLS");
				break;
              
            case 3:
				system("CLS");
				char tg;
				cout<<"输入学号:"<<endl;
				cin>>snum;
			    u=queryu(snum);
				m=querym(snum);
				d=queryd(snum);
				t=queryt(snum);
				do
				{
				system("CLS");
/*1*/   		if(u!=NULL)
				{
					int temp=-1;
					cout<<"名字          学号   图书编号     借阅日期        归还日期"<<endl;
					cout<<"本科生:"<<endl;
					u->show();
					cout<<"输入所要退的书的编号"<<endl;
					cin>>num;
					for (int i=0;i<=u->gettip();i++)
					{
						if (num==u->getbook_number(i))
						{
							temp=i;
							break;
						}
					}
					if(temp!=-1)
					{
						b=query_out(num);
							b->setif_borrow(false);
						if(u->gettip()==0)
						{
							u->book_back();;
							u->del_student();
							if(timejudge(u->getbook_turnyear(temp),u->getbook_turnmonth(temp),u->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
						else 
						{
							int t=temp;
							u->book_back();
							while(t<10)
							{
								u->setbook_number(t,u->getbook_number(t+1));
									t++;
							}
							if(timejudge(u->getbook_turnyear(temp),u->getbook_turnmonth(temp),u->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
					}
					else 
					{
						cout<<"请核对您的信息"<<endl;
						system("PAUSE");
						system("CLS");
						break;
					}
					}


/*2*/              else if(m!=NULL)
				{
					int temp=-1;
					cout<<"名字          学号   图书编号     借阅日期        归还日期"<<endl;
					cout<<"硕士研究生:"<<endl;
					m->show();
					cout<<"输入所要退的书的编号"<<endl;
					cin>>num;
					for (int i=0;i<=m->gettip();i++)
					{
						if (num==m->getbook_number(i))
						{
							temp=i;
							break;
						}
					}
					if(temp!=-1)
					{
						b=query_out(num);
							b->setif_borrow(false);
						if(m->gettip()==0)
						{
							m->book_back();
							m->del_student();
							if(timejudge(m->getbook_turnyear(temp),m->getbook_turnmonth(temp),m->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
						else 
						{
							int t=temp;
							m->book_back();
							while(t<10)
							{
								m->setbook_number(t,m->getbook_number(t+1));
									t++;
							}

							if(timejudge(m->getbook_turnyear(temp),m->getbook_turnmonth(temp),m->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
					}
					else 
					{
						cout<<"请核对您的信息"<<endl;
						system("PAUSE");
						system("CLS");
						break;
					}
					}


/*3*/   				else if(d!=NULL)
				{
					int temp=-1;
					cout<<"名字          学号   图书编号     借阅日期        归还日期"<<endl;
					cout<<"博士研究生:"<<endl;
					d->show();
					cout<<"输入所要退的书的编号"<<endl;
					cin>>num;
					for (int i=0;i<=d->gettip();i++)
					{
						if (num==d->getbook_number(i))
						{
							temp=i;
							break;
						}
					}
					if(temp!=-1)
					{
						b=query_out(num);
							b->setif_borrow(false);
						if(d->gettip()==0)
						{
							d->book_back();
							d->del_student();
							if(timejudge(d->getbook_turnyear(temp),d->getbook_turnmonth(temp),d->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
						else 
						{
							int t=temp;
							d->book_back();
							while(t<10)
							{
								d->setbook_number(t,d->getbook_number(t+1));
									t++;
							}

							if(timejudge(d->getbook_turnyear(temp),d->getbook_turnmonth(temp),d->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
					}
					else 
					{
						cout<<"请核对您的信息"<<endl;
						system("PAUSE");
						system("CLS");
						break;
					}
					}


/*4*/   			else	if(t!=NULL)
				{
					int temp=-1;
					cout<<"名字          学号   图书编号     借阅日期        归还日期"<<endl;
					cout<<"教师:"<<endl;
					t->show();
					cout<<"输入所要退的书的编号"<<endl;
					cin>>num;
					for (int i=0;i<=t->gettip();i++)
					{
						if (num==t->getbook_number(i))
						{
							temp=i;
							break;
						}
					}
					if(temp!=-1)
					{
						b=query_out(num);
							b->setif_borrow(false);
						if(t->gettip()==0)
						{
							t->book_back();
							t->del_student();


							if(timejudge(t->getbook_turnyear(temp),t->getbook_turnmonth(temp),t->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
						else 
						{
							int te=temp;
							t->book_back();
							while(te<10)
							{
								t->setbook_number(te,t->getbook_number(te+1));
									te++;
							}

							if(timejudge(t->getbook_turnyear(temp),t->getbook_turnmonth(temp),t->getbook_turnday(temp))==0)    //判断是否超期
								cout<<"您的书已超期,请缴纳相关费用"<<endl;
							cout<<"      退书成功"<<endl;
							system("PAUSE");
						}
					}
					else 
					{
						cout<<"请核对您的信息"<<endl;
						system("PAUSE");
						system("CLS");
						break;
					}
					}
             else 
			           {
					 cout<<"此学号的学生不在借书之列,请核对信息"<<endl;
                     system("PAUSE");
					 system("CLS");
					 break;
                          }
					
					cout<<"是否继续还书:"<<endl;
					tg=judge();
					}
                        while(tg=='y'||tg=='Y');
						system("CLS");
					break;
			case 4:
				system("CLS");
				while(1)
				{
				   int n=interface1();
							 if(n==1)
						{
						  system("CLS");
							cout<<"图书编号  图书条码    图书名    作者     出版社    出版时间   ISBN号 是否借出\n";
																disp();
						cout<<"                      输入图书编号:"<<endl;
						cin>>num;
						b=query(num);
							 if (b==NULL)
						{
							cout<<"                 该图书不存在"<<endl;
							continue;
						}
							 cout<<"图书编号  图书条码    图书名    作者     出版社    出版时间   ISBN号 是否借出 \n";
							  b->display();
							  system("PAUSE");
							  system("CLS");
						}
									else if(n==2)
									{
										system("CLS");
										cout<<"                    输入图书编号:"<<endl;
										cin>>num;
										b=query(num);
										if(b==NULL)
										{
											cout<<"                     该图书不存在"<<endl;
											continue;
										}
											cout<<"                     确定要删除此记录吗?(Y/N)"<<endl;
					                          char tg=judge();
										if(tg!='n'&&tg!='N')
										{
										b->del_book();
										cout<<"                        已成功删除该书记录!"<<endl;
										}
										system("CLS");
									}
													else if(n==3)
													{
														system("CLS");
														 cout<<"                      确定要清空所有记录吗?(Y/N)"<<endl;
														char tg=judge();
														if(tg!='n'&&tg!='N')
														{
														clear();
														cout<<"                       已成功清空记录!"<<endl;
														system("PAUSE");
													
														}
														system("CLS");
													}
													else if(n==4)
													{
														system("CLS");
																cout<<"图书编号  图书条码    图书名    作者     出版社    出版时间   ISBN号 是否借出\n";
																disp();
																system("PAUSE");
																system("CLS");
													}
													else if(n==5)
													{
														system("CLS");
														       cout<<"图书编号  图书条码    图书名    作者     出版社    出版时间   ISBN号 是否借出\n";
																dispout();
																system("PAUSE");
																system("CLS");
													}
													else if(n==6)
													{
														system("CLS");
														       cout<<"图书编号  图书条码    图书名    作者     出版社    出版时间   ISBN号 是否借出\n";
																displeft();
																system("PAUSE");
																system("CLS");
													}
													else if(n==0)
														{
															system("CLS");
															break;
													}
				}
				system("CLS");
				break;
			case 5:
				system("CLS");
				cout<<"名字"<<setw(15)<<"学号"<<setw(10)<<"图书编号"<<setw(10)<<"借阅日期"<<setw(20)<<"归还日期"<<endl;

				cout<<"本科生:"<<endl;
				dispu();
				cout<<"硕士研究生:"<<endl;
				dispm();
				cout<<"博士研究生:"<<endl;
				dispd();
				cout<<"教师:"<<endl;
				dispt();
				system("PAUSE");
				system("CLS");
				break;



/*标记*/    case 6:
	             system("CLS");
	             int i,j;
				 cout<<"名字"<<setw(15)<<"学号"<<setw(10)<<"图书编号"<<setw(10)<<"借阅日期"<<setw(20)<<"归还日期"<<endl;
				 for(i=0;i<=topu;i++)
					 for(j=0;j<=ug[i].gettip();j++)
					 {
						 if(timejudge(ug[i].getbook_turnyear(j),ug[i].getbook_turnmonth(j),ug[i].getbook_turnday(j))==0)    //判断是否超期
						
						 ug[i].showone(j);
					 }
				 system("PAUSE");
				 system("CLS");
				 break;

            case 7:
				system("CLS");
			cout<<"图书编号  图书条码    图书名    作者     出版社    出版时间   ISBN号 是否借出\n";
				for(i=0;i<=topu;i++)
					 for(j=0;j<=ug[i].gettip();j++)
					 {
						 if(timejudge(ug[i].getbook_turnyear(j),ug[i].getbook_turnmonth(j),ug[i].getbook_turnday(j))==0)    //判断是否超期
						 {
						b=query(ug[i].getbook_number(j));
						 b->display();
						 }
					 }
					 system("PAUSE");
					 system("CLS");
				break;
			case 0:
				system("CLS");
				break;
			default:cout<<"                        输入错误";
				system("PAUSE");
				system("CLS");
				break;
		}
	}
	system("CLS");
}

//主函数
void main()
{    
	int choice=1;
	Bdeal deal;
	while(choice)
	{     	
		  choice=welcome_interface1();
			switch(choice)
			{
			case 1:
				    system("CLS");
					deal.handle();
					break; 
            case 0:
				system("CLS");
				leave_interface();
				 break;
			default:cout<<"                     输入错误,请重新输入:";
			}
	}
}

int main_interface()    //主界面
{
	int choice;
	      cout<<"             ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n";  
		  cout<<"             ┃  ┃         图书管理系统      by --王川  ┃  ┃\n";
		  cout<<"             ┃  ┗━━━━━━━━━━━━━━━━━━━┛  ┃\n";
		  cout<<"             ┃               ●[1]新书入库                  ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[2]借书                      ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[3]还书                      ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[4]查询图书                  ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[5]查询读者                  ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[6]显示所有超期读者          ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[7]显示所有超期图书          ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[0]退出系统                  ┃\n";
		  cout<<"             ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n";
	   do
	{
		cout<<"输入你要执行的操作:";
		cin>>choice;
	}
	while(choice<0||choice>7);
	return choice;
}

int welcome_interface1()
{
	      int choice;
	      cout<<"\n\n";
		  cout<<"             ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n";  
		  cout<<"             ┃  ┃                                      ┃  ┃\n";
		  cout<<"             ┃  ┃           欢迎使用图书管理系统       ┃  ┃\n";
		  cout<<"             ┃  ┃                                      ┃  ┃\n";
		  cout<<"             ┃  ┗━━━━━━━━━━━━━━━━━━━┛  ┃\n";
		  cout<<"             ┃                               by --王川      ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃           ●[1]进入                          ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                           ●[0]退出          ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n";

			do
	{
		cout<<"输入你要执行的操作:";
		cin>>choice;
	}
	while(choice<0||choice>1);
			return choice;
}

void leave_interface()
{
	      cout<<"\n\n";
		  cout<<"             ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n";  
		  cout<<"             ┃  ┃                                      ┃  ┃\n";
		  cout<<"             ┃  ┃           感谢使用图书管理系统       ┃  ┃\n";
		  cout<<"             ┃  ┃                                      ┃  ┃\n";
		  cout<<"             ┃  ┗━━━━━━━━━━━━━━━━━━━┛  ┃\n";
		  cout<<"             ┃                               by --王川      ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                ●         ●                 ┃\n";
		  cout<<"             ┃              ●   ●    ●  ●               ┃\n";
		  cout<<"             ┃            ●        ●        ●            ┃\n";
		  cout<<"             ┃          ●                      ●          ┃\n";
		  cout<<"             ┃         ●        感谢使用!      ●         ┃\n";
		  cout<<"             ┃           ●                    ●           ┃\n";
		  cout<<"             ┃             ●                ●             ┃\n";
		  cout<<"             ┃               ●            ●               ┃\n";
		  cout<<"             ┃                  ●      ●                  ┃\n";
		  cout<<"             ┃                      ●                      ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n";
}

char judge()
{
	char tg;
	do
	{
	cin>>tg;
	}
	while(tg!='y'&&tg!='Y'&&tg!='n'&&tg!='N');
	return tg;
}

int interface1()
{
	     int choice;
	      cout<<"             ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n";  
		  cout<<"             ┃  ┃         图书管理系统      by --王川  ┃  ┃\n";
		  cout<<"             ┃  ┗━━━━━━━━━━━━━━━━━━━┛  ┃\n";
		  cout<<"             ┃               ●[1]查找图书                  ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[2]删除指定图书              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[3]删除全部图书              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[4]显示全部图书              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[5]显示借走图书              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[6]显示未借图书              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃               ●[0]返回上级菜单              ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n";
		    do
	{
		cout<<"输入你要执行的操作:";
		cin>>choice;
	}
	while(choice<0||choice>6);
	return choice;
}
int interface2()
{
	      int choice;
	      cout<<"             ┏━┓━━━━━━━━━━━━━━━━━━━┏━┓\n";  
		  cout<<"             ┃  ┃         图书管理系统      by --王川  ┃  ┃\n";
		  cout<<"             ┃  ┗━━━━━━━━━━━━━━━━━━━┛  ┃\n";
		  cout<<"             ┃        ●请问你是:                          ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                ●[1]本科生                   ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                ●[2]硕士研究生               ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                ●[3]博士研究生               ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                ●[4]教师                     ┃\n";
		  cout<<"             ┃                                              ┃\n";
		  cout<<"             ┃                ●[0]返回上级菜单             ┃\n";
		  cout<<"             ┗━━━━━━━━━━━━━━━━━━━━━━━┛\n";
		    do
	{
		cout<<"输入你要执行的操作:";
		cin>>choice;
	}
	while(choice<0||choice>4);
	return choice;
}

void count(int days,int &year,int &month,int &day)
{
	int sig=0;
	day=day+days;
	while(day>=28)
	{
		if ((year%4==0)&&(year%100!=0)||(year%400==0))sig=1;
		switch(month)
		{
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
			if(day>31)
				{
					month++;
					day-=31;
			    }
			else break;
		case 2:
			if(sig==1&&day>29)
			{
				    month++;
					day-=29;
			}
			else if(day>28)
			{
				 month++;
				day-=28;
			}
			else break;
		case 4:
		case 6:
		case 9:
		case 11:
			if(day>30)
			{
				month++;
				day-=30;
			}
			else break;
		case 12:
			if(day>31)
			{
				year++;
				month=1;
				day-=31;
			}
			else break;
		}
	}
}

void getSystemTime(int &year,int &month,int &day) 
{ 
 time_t timer; 
 time(&timer); 
 tm* t_tm = localtime(&timer); 
 
 year=t_tm->tm_year+1900;
 month=t_tm->tm_mon+1;
 day=t_tm->tm_mday;
} 

int timejudge(int year,int month,int day)//到期的年月日  返回是否超期   0超期  1  未超期
{
	int y,m,d;
	getSystemTime(y,m,d);
	if(y<year)return 1;
	else 
	{
		if(y==year)
		{
			if(m<month)return 1;
			else
			{
				if(m==month)
				{
					if(d<=day)
						return 1;
					else return 0;
				}
				else return 0;
			}
		}
		else return 0;
	}
}




王川
2014/2/28