#include <iostream> #include <cstring> using namespace std;  const int h=4; const int size=20; class book { 	public: 	friend class member; 	int shabak; 	string onvan; 	string mozo; 	string nevisande; 	bool amanat; 	bool r; 	int tba;//tedade bari ke amanat rafte 	book() 	{ 		amanat = r=false; 		tba=0; 		 	} 	void add() 	{ 		cout<<"onvan ra vared konid"<<endl; 		cin>>onvan; 		cout<<"nevisande ra vared konid"<<endl; 		cin>>nevisande; 		cout<<"shabak ra vared konid"<<endl; 		cin>>shabak; 		cout<<"mozo ra vared konid"<<endl; 		cin>>mozo; 	} 	void print() 	{	 		cout<<onvan<<"\t"<<nevisande<<"\t"<<shabak<<"\t"<<mozo<<"\n"; 	} }; class member { 	public: 	string esm,famil,npedar; 	int id,tt; 	int lketab[h]; 	int lketabr[h]; 	int tk;//tedade ketab haee ke ye fard dare; 	int tkr;//tedade ketab haee ke ye fard reserve karde 	int tba;//tedae bari ke ketab amanat gerefte 	member () 	{ 	       tkr=0; 		tk=0; 		tba=0; 	} 	void add() 	{ 		cout <<"Enter id "<<endl; 		cin>>id; 		cout <<"esm ra vared konid"<<endl; 		cin>>esm; 		cout <<"family ra vared konid"<<endl; 		cin>>famil; 		cout <<"name pedar ra vared konid"<<endl; 		cin>>npedar; 		cout <<"tarikh tavalod ra vared konid"<<endl; 		cin>>tt; 	} 	void print() 	{	 		cout<<id<<"\t\t"<<esm<<"\t\t"<<famil<<"\t\t"<<npedar<<"\t\t"<<tt<<"\n"; 	} 	 };  int main() { 	book b[size]; 	member m[size]; 	int x; 	int bc=0;//tedade ketabA 	int mc=0;//tedade azA 	do{ 	cout << "1) Add a Book."<<endl; 	cout<<""<<endl; 	cout << "2) Search a book by title ."<<endl; 	cout<<""<<endl; 	cout << "3) delete a book by title"<<endl; 	cout<<""<<endl; 	cout << "4) edit a book by title "<<endl; 	cout<<""<<endl; 	cout << "5) Add member."<<endl; 	cout<<""<<endl; 	cout << "6) delete a member by id"<<endl; 	cout<<""<<endl; 	cout << "7) edit a member by id"<<endl; 	cout<<""<<endl; 	cout << "8) get a book "<<endl; 	cout<<""<<endl; 	cout << "9) return a book "<<endl; 	cout<<""<<endl; 	cout << "10) reserve book "<<endl; 	cout<<""<<endl; 	cout << "11) por makhatab tarin ketab"<<endl; 	cout<<""<<endl; 	cout << "12) faAll tarin ozv "<<endl; 	cout<<""<<endl; 	cout << "13) list ketabhaye amanati"<<endl; 	cout<<""<<endl; 	cout << "14) list ketabhaye reservi"<<endl; 	cout<<""<<endl; 	cout << "15) list ketabhaye amanaT yek ozv"<<endl; 	cout<<""<<endl; 	cout << "16) list ketabhaye mojood dar ketab khane"<<endl; 	cout<<""<<endl; 	cout << "17) list azAee ketab khane"<<endl; 	cout<<""<<endl; 	cout <<"Enter (1-17) or 0 to exit "<<endl; 	cin>>x; 	 	switch(x) 	{ 		case 1: 		{ 			b[bc].add(); 			bc++; 			break; 		} 		case 2: 		{ 			bool be=false; 			//jostojo bar asase esm ketab 			string a; 			cout <<"Enter title for search "<<endl; 			cin>>a; 			cout<<"title\tnevisande\tshabak\tmozo\n"; 			int i; 			for (i=0;i<size and !be;i++) 			{ 				if (b[i].onvan==a) 				{b[i].print();be=true;} 			} 			if (be==false) 			cout<<"ketab nist"<<endl; 			break; 		} 		case 3: 		{ 			bool be=false; 			//hazve ketab 			string a; 			cout <<"Enter title for delete "<<endl; 			cin>>a; 			int i; 			for (i=0;i<size and !be;i++) 			{ 				if (b[i].onvan==a) 				{ 					be=true; 					for (int j=i;j<size;j++) 						b[i]=b[i+1]; 				} 			} 			bc--; 			if (be==false) 			{cout<<"ketab nist"<<endl;bc++;} 				break; 		} 		case 4: 		{ 			bool be=false; 			//virayesh bar asase onavan 			string a; 			cout <<"Enter title for edit "<<endl; 			cin>>a; 			int i; 			for ( i=0;i<size and !be;i++) 			{ 				if (b[i].onvan==a) 				{ 					cout<<"etelate virayesh shode: \n"; 					b[i].add(); 					be=true; 				} 			} 			 			if (be==false) 				cout<<"ketab nist"<<endl; 			break; 		} 		case 5: 		{ 			//add ozve 			m[mc].add(); 			mc++; 			break; 		} 		case 6: 		{ 			//hazve aza bara asase id 			int id; 			cout <<"Enter id for delete "<<endl; 			cin>>id; 			int i; 			bool be=false; 			for (i=0;i<size and !be ;i++) 			{ 				if (m[i].id==id) 				{ 					for (int j=i;j<size;j++) 						m[i]=m[i+1]; 					be=true; 				} 				 			} 			mc--; 			if (be==false) 			{cout<<"ketab nist"<<endl;mc++;} 			break; 		} 		case 7: 		{ 			//virayesh bar asase esm 			int id; 			bool be=false; 			cout <<"Enter id for edit"<<endl; 			cin>>id; 			int i; 			for ( i=0;i<size and !be;i++) 			{ 				if (m[i].id==id) 				{ 					cout<<"etelate edite shode:\n"; 					m[i].add(); 					be=true; 				} 			} 			if (be==false) 			  cout<<"azv vojod nadard"<<endl; 			break; 		} 		case 8: 		{ 			//gereftan ketab 			int id; 			cout <<"Enter id for get book"<<endl; 			cin>>id; 			string onvan; 			cout <<"Enter title book for get book"<<endl; 			cin>>onvan; 			for(int i=0;i<mc;i++) 				if(m[i].id == id ) 				{ 					m[i].tba++;//tedad bari ke ketab amanat migire ro yeki + kon 					for(int j=0;j<size;j++) 					if (b[j].onvan==onvan ) 					{ 						if (b[j].amanat==true) 						cout<<"ketab biroone"; 						else 						{ 						m[i].lketab[m[i].tk]=b[j].shabak; 						m[i].tk++; 						b[j].tba++; 						b[j].amanat=true; 						} 					} 					 				} 			break; 		} 		case 9: 		{ 			//bazgashte ketab 			int id; 			cout <<"Enter id"<<endl; 			cin>>id; 			string onvan; 			cout <<"Enter title ketabe bazgashti"<<endl; 			cin>>onvan; 			bool be=false;  			for(int i=0;i<size and  !be;i++) 				if(m[i].id == id ) 				{ 					for(int j=0;j<size and !be;j++) 					if (b[j].onvan==onvan ) 					{ 						b[j].amanat=false; 						//to liste ketab haye ye fard josto jo kon va ketab ba in onvan ro hazv kon 						 						for (int k=0;k<m[i].tk and !be;k++) 						if (m[i].lketab[k]==b[j].shabak) 						{ 							//ketab ro hazzv kon 							for(int f=k;k<m[i].tk and !be;f++) 								m[i].lketab[f]=m[i].lketab[f+1]; 							m[i].tk--; 							be =true; 						} 					} 					 				} 				 			break; 			 		} 		case 10: 		{ 			//reserve ketab 			int id; 			cout <<"Enter id for reseve "<<endl; 			cin>>id; 			string onvan; 			cout <<"Enter title ketab for reseve "<<endl; 			cin>>onvan; 			for(int i=0;i<mc;i++) 				if(m[i].id == id ) 				{ 					for(int j=0;j<size;j++) 					if (b[j].onvan==onvan ) 					{ 						m[i].lketabr[m[i].tkr]=b[j].shabak; 						m[i].tkr++; 						b[j].r=true; 					} 					 				} 			break; 		} 		case 11: 		{ 			//por mokhatab tarin ketab 			int max1=0; 			for(int i=0;i<size;i++) 				max1=max(max1,b[i].tba); 			for(int i=0;i<size;i++) 				if (b[i].tba==max1) 				cout<<"por mokhatab tarin ketab :   "<<b[i].onvan<<endl; 			break; 		} 		case 12: 		{ 			//faAltarin aza 			int max1=0; 			for(int i=0;i<size;i++) 				max1=max(max1,m[i].tba); 			for(int i=0;i<size;i++) 				if (m[i].tba==max1) 				cout<<"faAltarin aza :"<<m[i].esm<<"\t"<<m[i].famil<<endl; 			break; 		} 		case 13: 		{          //list ketabe amanati 			cout<<"title\tnevisande\tshabak\tmozo\n"; 			for(int i=0;i<bc;i++) 				if (b[i].amanat==true) 					b[i].print(); 			break; 		} 		case 14: 		{       //list ketabe reservi 			cout<<"title\tnevisande\tshabak\tmozo\n"; 			for(int i=0;i<bc;i++) 				if (b[i].r==true) 					b[i].print(); 			break; 		} 		case 15: 		{        //liste ketab haye amanaT aza 			int id; 			cout<<"shomare ozviat ? :"; 			cin>>id; 			cout<<"liste ketab haye amanaT farde morede nazar:"<<endl; 			cout<<"title\tnevisande\tshabak\tmozo\n"; 			bool be = false; 			for(int i=0;i<size;i++) 				if (m[i].id ==id) 				{ 					for(int j=0;j<m[i].tk and  !be;j++) 					for (int f=0;f<size and  !be;f++) 						if (m[i].lketab[j]==b[f].shabak) 						{b[f].print();be=true;} 				} 			break; 		} 		case 16: 		{       //list ketabe  mojod 			cout<<"list ketabhaye mojood dar ketab khane"<<endl; 			cout<<"title\tnevisande\tshabak\tmozo\n"; 			for(int i=0;i<bc;i++) 				if (b[i].amanat==false) 					b[i].print(); 			break; 		} 		case 17: 		{       // list aza 			cout <<"id\tesm\tfamili\tnamepedar\tarikh tavalod\n"; 			for(int i=0;i<mc;i++) 					m[i].print(); 			 			break; 		} 		 	} 	}while(x!=0); 	return 0; }