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

📄 book_library.cpp

📁 Contains a project related to the managment of a Telephone Directory... Feel free to download and us
💻 CPP
📖 第 1 页 / 共 3 页
字号:

void WORKING :: issue_b(void)
{
	BOOK B ;
	MEMBER M ;
	DATE D ;
	char t1code[33], ch ;
	int t2code=0, tcode=0, mcode=0 ;
	int valid ;
	int d1, m1, y1 ;
	struct date d;
	getdate(&d);
	d1 = d.da_day ;
	m1 = d.da_mon ;
	y1 = d.da_year ;
	do
	{
		valid = 1 ;
		while (1)
		{
			clrscr() ;
			gotoxy(5,2) ;
			cout <<"DATE : " <<d1 <<"/" <<m1 <<"/" <<y1 ;
			gotoxy(72,1) ;
			cout <<"<0>=EXIT" ;
			gotoxy(5,5) ;
			cout <<"ENTER CODE OR NAME OF THE BOOK TO BE ISSUED " ;
			gotoxy(5,6) ;
			cout <<"                  OR                       " ;
			gotoxy(5,7) ;
			cout <<"PRESS  <ENTER> FOR HELP  " ;
			gets(t1code) ;
			if (t1code[0] == '0')
				return ;
			if (strlen(t1code) == 0)
				B.table() ;
			else
				break ;
		}
		t2code = atoi(t1code) ;
		tcode = t2code ;
		if ((tcode == 0 && !b_name_found(t1code)) || (tcode != 0 && !b_found(tcode)))
		{
			valid = 0 ;
			gotoxy(5,10) ;
			cout <<"\7RECORD NOT FOUND" ;
			gotoxy(5,11) ;
			cout <<"PRESS <ESC> TO EXIT OR ANY OTHER KEY TO CONTINUE..." ;
			ch = getch() ;
			if (ch == 27)
				return ;
		}
	} while (!valid) ;
	if (tcode == 0)
		tcode = b_codeof(t1code) ;
	if (!available(tcode))
	{
		gotoxy(5,10) ;
		cout <<"\7SORRY! BOOK (" <<b_name(tcode) <<") IS NOT AVAILABLE" ;
		gotoxy(5,11) ;
		cout <<"KINDLY ISSUE ANY OTHER BOOK" ;
		gotoxy(5,12) ;
		cout <<"SEE LIST OF BOOKS" ;
		getch() ;
		return ;
	}
	do
	{
		valid = 1 ;
		while (1)
		{
			clrscr() ;
			gotoxy(72,1) ;
			cout <<"<0>=EXIT" ;
			gotoxy(5,2) ;
			cout <<"DATE : " <<d1 <<"/" <<m1 <<"/" <<y1 ;
			gotoxy(5,5) ;
			cout <<"BOOK NAME: " <<b_name(tcode) ;
			gotoxy(5,7) ;
			cout <<"ENTER CODE NO. OF THE MEMBER" ;
			gotoxy(5,8) ;
			cout <<"            OR              " ;
			gotoxy(5,9) ;
			cout <<"PRESS <ENTER> FOR HELP " ;
			gets(t1code) ;
			if (t1code[0] == '0')
				return ;
			if (strlen(t1code) == 0)
				M.jot() ;
			else
				break ;
		}
		t2code = atoi(t1code) ;
		mcode = t2code ;
		if (mcode == 0)
		{
			valid = 0 ;
			gotoxy(5,25) ;
			cout <<"\7ENTER CORRECTLY" ;
			getch() ;
		}
		if (!m_found(mcode) && valid)
		{
			valid = 0 ;
			gotoxy(5,13) ;
			cout <<"\7RECORD NOT FOUND" ;
			gotoxy(5,14) ;
			cout <<"PRESS <ESC> TO EXIT OR ANY OTHER KEY TO CONTINUE..." ;
			ch = getch() ;
			if (ch == 27)
				return ;
		}
	} while (!valid) ;
	int tcopies, tavail ;
	tcopies = no_of_copies(tcode) ;  // member function of BOOK
	tavail  = available(tcode) - 1 ;  // member function of BOOK
	update_copies(tcode,tcopies,tavail) ;  // member function of BOOK
	D.ex_date(d1,m1,y1,15) ;
	d1 = D.day ;
	m1 = D.mon ;
	y1 = D.year ;
	update_b(mcode,tcode,d1,m1,y1) ;  // member function of MEMBER
	gotoxy(5,13) ;
	cout <<"\7BOOK IS ISSUED TO :" <<m_name(mcode) ;
	gotoxy(5,15) ;
	cout <<"DATE OF RETURN : " <<d1 <<"/" <<m1 <<"/" <<y1 ;
	getch() ;
}

// THIS FUNCTION RETURNS THE BOOK FOR THE MEMBER

void WORKING :: return_b(void)
{
	MEMBER M ;
	char t1code[5], ch ;
	int t2code=0, mcode=0, valid ;
	int d1, m1, y1 ;
	struct date d;
	getdate(&d);
	d1 = d.da_day ;
	m1 = d.da_mon ;
	y1 = d.da_year ;
	do
	{
		valid = 1 ;
		while (1)
		{
			clrscr() ;
			gotoxy(72,1) ;
			cout <<"<0>=EXIT" ;
			gotoxy(5,2) ;
			cout <<"DATE : " <<d1 <<"/" <<m1 <<"/" <<y1 ;
			gotoxy(5,7) ;
			cout <<"ENTER CODE NO. OF MEMBER WHO WANTS TO RETURN THE BOOK" ;
			gotoxy(5,8) ;
			cout <<"                        OR              " ;
			gotoxy(5,9) ;
			cout <<"PRESS <ENTER> FOR HELP  " ;
			gets(t1code) ;
			if (t1code[0] == '0')
				return ;
			if (strlen(t1code) == 0)
				M.jot() ;
			else
				break ;
		}
		t2code = atoi(t1code) ;
		mcode = t2code ;
		if (mcode == 0)
		{
			valid = 0 ;
			gotoxy(5,25) ;
			cout <<"\7ENTER CORRECTLY" ;
			getch() ;
		}
		if (!m_found(mcode) && valid)
		{
			valid = 0 ;
			gotoxy(5,13) ;
			cout <<"\7RECORD NOT FOUND" ;
			gotoxy(5,14) ;
			cout <<"PRESS <ESC> TO EXIT OR ANY OTHER KEY TO CONTINUE..." ;
			ch = getch() ;
			if (ch == 27)
				return ;
		}
		if (!issued(mcode) && valid)
		{
			valid = 0 ;
			gotoxy(5,13) ;
			cout <<"\7MEMBER HAVE NO BOOK TO RETURN" ;
			gotoxy(5,14) ;
			cout <<"PRESS <ESC> TO EXIT OR ANY OTHER KEY TO CONTINUE...";
			ch = getch() ;
			if (ch == 27)
				return ;
		}
	} while (!valid) ;
	int bcode, tcopies, tavail ;
	bcode = issued(mcode) ;
	gotoxy(5,13) ;
	cout <<"BOOK CODE : " <<bcode ;
	gotoxy(5,14) ;
	cout <<"BOOK NAME : " <<b_name(bcode) ;
	tcopies = no_of_copies(bcode) ;
	tavail = available(bcode) + 1 ;
	int f ;
	f = fine(mcode) ;
	if (f != 0)
	{
		gotoxy(5,16) ;
		cout <<"YOU HAVE TO PAY A FINE OF RS." <<f ;
		gotoxy(5,17) ;
		cout <<"PLEASE DO NOT DELAY THE RETURN OF BOOK AGAIN" ;
	}
	update_copies(bcode,tcopies,tavail) ;
	update_b(mcode,0,0,0,0) ;
	gotoxy(5,19) ;
	cout <<"\7BOOK HAS BEEN RETURNED" ;
	getch() ;
}

// THIS FUNCTION GIVES DATA TO MODIFY THE BOOK RECORD

void WORKING :: modify_b(void)
{
	BOOK B ;
	char t1code[5], tname[33], tauthor[26], *t1, ch ;
	int t2code=0, tcode=0 ;
	float t2=0.0, tprice=0.0 ;
	int valid ;
	do
	{
		valid = 1 ;
		while (1)
		{
			clrscr() ;
			gotoxy(72,1) ;
			cout <<"<0>=Exit" ;
			gotoxy(5,5) ;
			cout <<"ENTER CODE OR NAME OF THE BOOK TO BE MODIFIED " ;
			gotoxy(5,6) ;
			cout <<"                  OR                       " ;
			gotoxy(5,7) ;
			cout <<"PRESS <ENTER> FOR HELP  " ;
			gets(t1code) ;
			if (t1code[0] == '0')
				return ;
			if (strlen(t1code) == 0)
				B.table() ;
			else
				break ;
		}
		t2code = atoi(t1code) ;
		tcode = t2code ;
		if ((tcode == 0 && !b_name_found(t1code)) || (tcode != 0 && !b_found(tcode)))
		{
			valid = 0 ;
			gotoxy(5,10) ;
			cout <<"\7RECORD NOT FOUND" ;
			gotoxy(5,11) ;
			cout <<"PRESS <ESC> TO EXIT OR ANY OTHER KEY TO CONTINUE...";
			ch = getch() ;
			if (ch == 27)
				return ;
		}
	} while (!valid) ;
	if (tcode == 0)
		tcode = b_codeof(t1code) ;
	clrscr() ;
	gotoxy(72,1) ;
	cout <<"<0>=EXIT" ;
	BOOK::display(tcode) ;
	do
	{
		gotoxy(5,13) ; clreol() ;
		cout <<"DO YOU WANT TO MODIFY THIS RECORD  (Y/N) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
		if (ch == '0')
			return ;
	} while (ch != 'Y' && ch != 'N') ;
	if (ch == 'N')
		return ;
	gotoxy(5,16) ;
	cout <<"BOOK NAME   : " ;
	gotoxy(5,17) ;
	cout <<"AUTHOR NAME : " ;
	gotoxy(5,18) ;
	cout <<"PRICE        : RS." ;
	do
	{
		valid = 1 ;
		gotoxy(5,25) ; clreol() ;
		cout <<"ENTER THE NAME OF THE BOOK OR <ENTER> FOR NO CHANGE" ;
		gotoxy(19,16) ; clreol() ;
		gets(tname) ;
		strupr(tname) ;
		if (tname[0] == '0')
			return ;
		if (strlen(tname) > 32)
		{
			valid = 0 ;
			gotoxy(5,25) ; clreol() ;
			cout <<"\7ENTER CORRECTLY (RANGE: 1..32)" ;
			getch() ;
		}
	} while (!valid) ;
	if (strlen(tname) == 0)
		strcpy(tname,b_name(tcode)) ;
	do
	{
		valid = 1 ;
		gotoxy(5,25) ; clreol() ;
		cout <<"ENTER AUTHOR'S NAME OR <ENTER> FOR NO CHANGE" ;
		gotoxy(19,17) ; clreol() ;
		gets(tauthor) ;
		strupr(tauthor) ;
		if (tauthor[0] == '0')
			return ;
		if (strlen(tauthor) > 25)
		{
			valid = 0 ;
			gotoxy(5,25) ; clreol() ;
			cout <<"\7ENTER CORRECTLY (RANGE: 1..25)" ;
			getch() ;
		}
	} while (!valid) ;
	if (strlen(tauthor) == 0)
		strcpy(tauthor,a_name(tcode)) ;
	do
	{
		valid = 1 ;
		gotoxy(5,25) ; clreol() ;
		cout <<"ENTER PRICE OR <ENTER> FOR NO CHANGE" ;
		gotoxy(22,18) ; clreol() ;
		gets(t1) ;
		t2 = atof(t1) ;
		tprice = t2 ;
		if (t1[0] == '0')
			return ;
		if (strlen(t1) == 0)
			break ;
		if (tprice < 1 || tprice > 9999)
		{
			valid = 0 ;
			gotoxy(5,25) ; clreol() ;
			cout <<"\7ENTER CORRECTLY" ;
			getch() ;
		}
	} while (!valid) ;
	if (strlen(t1) == 0)
		tprice = b_price(tcode) ;
	gotoxy(5,25) ; clreol() ;
	do
	{
		gotoxy(5,20) ; clreol() ;
		cout <<"DO YOU WANT TO SAVE THE CHANGES (Y/N) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
		if (ch == '0')
			return ;
	} while (ch != 'Y' && ch != 'N') ;
	if (ch == 'N')
		return ;
	BOOK::change(tcode,tname,tauthor,tprice) ;
	gotoxy(5,23) ;
	cout <<"\7RECORD MODIFIED" ;
	getch() ;
}

// THIS FUNCTION GIVES DATA TO MODIFY THE MEMBER RECORD

void WORKING :: modify_m(void)
{
	MEMBER M ;
	char m1code[10], mname[26], mphone[10], maddress[33], ch ;
	int m2code=0, mcode=0 ;
	int valid ;
	do
	{
		valid = 1 ;
		while (1)
		{
			clrscr() ;
			gotoxy(72,1) ;
			cout <<"<0>=EXIT" ;
			gotoxy(5,7) ;
			cout <<"ENTER CODE NO. OF THE MEMBER TO BE MODIFIED" ;
			gotoxy(5,8) ;
			cout <<"                        OR              " ;
			gotoxy(5,9) ;
			cout <<"PRESS <ENTER> FOR HELP  " ;
			gets(m1code) ;
			m2code = atoi(m1code) ;
			mcode = m2code ;
			if (m1code[0] == '0')
				return ;
			if (strlen(m1code) == 0)
				M.jot() ;
			else
				break ;
		}
		if (mcode == 0)
		{
			valid = 0 ;
			gotoxy(5,25) ;
			cout <<"\7ENTER CORRECTLY" ;
			getch() ;
		}
		if (valid && !m_found(mcode))
		{
			valid = 0 ;
			gotoxy(5,13) ;
			cout <<"\7RECORD NOT FOUND" ;
			gotoxy(5,14) ;
			cout <<"PRESS <ESC> TO EXIT OR ANY OTHER KEY TO CONTINUE...";
			ch = getch() ;
			if (ch == 27)
				return ;
		}
	} while (!valid) ;
	clrscr() ;
	gotoxy(72,1) ;
	cout <<"<0>=EXIT" ;
	MEMBER::display(mcode) ;
	do
	{
		gotoxy(5,10) ; clreol() ;
		cout <<"DO YOU WANT TO MODIFY THIS RECORD (Y/N) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
		if (ch == '0')
			return ;
	} while (ch != 'Y' && ch != 'N') ;
	if (ch == 'N')
		return ;
	gotoxy(5,13) ;
	cout <<"NAME    : " ;
	gotoxy(5,14) ;
	cout <<"PHONE   : " ;
	gotoxy(5,15) ;
	cout <<"ADDRESS : " ;
	do
	{
		valid = 1 ;
		gotoxy(5,25) ; clreol() ;
		cout <<"ENTER THE NAME OF MEMBER OR <ENTER> FOR NO CHANGE" ;
		gotoxy(19,13) ; clreol() ;
		gets(mname) ;
		strupr(mname) ;
		if (mname[0] == '0')
			return ;
		if (strlen(mname) > 25)
		{
			valid = 0 ;
			gotoxy(5,25) ; clreol() ;
			cout <<"\7ENTER CORRECTLY (RANGE: 1..25)" ;
			getch() ;
		}
	} while (!valid) ;
	if (strlen(mname) == 0)
		strcpy(mname,m_name(mcode)) ;
	do
	{
		valid = 1 ;
		gotoxy(5,25) ; clreol() ;
		cout <<"ENTER THE PHONE NO.OF MEMBER OR <ENTER> FOR NO CHANGE" ;
		gotoxy(19,14) ; clreol() ;
		gets(mphone) ;
		if (mphone[0] == '0')
			return ;
		if ((strlen(mphone) < 7 && strlen(mphone) > 0) || (strlen(mphone) > 9))
		{
			valid = 0 ;
			gotoxy(5,25) ; clreol() ;
			cout <<"\7ENTER CORRECTLY" ;
			getch() ;
		}
	} while (!valid) ;
	if (strlen(mphone) == 0)
		strcpy(mphone,m_phone(mcode)) ;
	do
	{
		valid = 1 ;
		gotoxy(5,25) ; clreol() ;
		cout <<"ENTER THE ADDRESS OF THE MEMBER OR <ENTER> FOR NO CHANGE" ;
		gotoxy(19,15) ; clreol() ;
		gets(maddress) ;
		strupr(maddress) ;
		if (maddress[0] == '0')
			return ;
		if (strlen(maddress) > 32)
		{
			valid = 0 ;
			gotoxy(5,25) ; clreol() ;
			cout <<"\7ENTER CORRECTLY (RANGE: 1..32)" ;
			getch() ;
		}
	} while (!valid) ;
	if (strlen(maddress) == 0)
		strcpy(maddress,m_address(mcode)) ;
	gotoxy(5,25) ; clreol() ;
	do
	{
		gotoxy(5,18) ; clreol() ;
		cout <<"DO YOU WANT TO SAVE CHANGES (Y/N) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
		if (ch == '0')
			return ;
	} while (ch != 'Y' && ch != 'N') ;
	if (ch == 'N')
		return ;
	MEMBER::mod(mcode,mname,mphone,maddress) ;
	gotoxy(5,23) ;
	cout <<"\7RECORD MODIFIED" ;
	getch() ;
}

// THIS FUNCTION GIVES BOOK CODE TO DELETE THE BOOK RECORD

void WORKING :: delete_b(void)
{
	BOOK B ;
	char t1code[5], tname[33], tauthor[26], ch ;
	int t2code=0, tcode=0 ;
	int valid ;
	do
	{
		valid = 1 ;
		while (1)
		{
			clrscr() ;
			gotoxy(72,1) ;
			cout <<"<0>=EXIT" ;
			gotoxy(5,5) ;
			cout <<"ENTER CODE OR NAME OF BOOK TO BE DELETED" ;
			gotoxy(5,6) ;
			cout <<"                  OR                       " ;
			gotoxy(5,7) ;
			cout <<"PRESS <ENTER> FOR HELP  " ;
			gets(t1code) ;
			if (t1code[0] == '0')
				return ;
			if (strlen(t1code) == 0)
				B.table() ;
			else
				break ;
		}
		t2code = atoi(t1code) ;
		tcode = t2code ;
		if ((tcode == 0 && !b_name_found(t1code)) || (tcode != 0 && !b_found(tcode)))
		{
			valid = 0 ;
			gotoxy(5,10) ;
			cout <<"\7RECORD NOT FOUND" ;
			gotoxy(5,11) ;
			cout <<"PRESS <ESC> TO EXIT OR ANY OTHER KEY TO CONTINUE...";
			ch = getch() ;
			if (ch == 27)
				return ;
		}
	} while (!valid) ;
	if (tcode == 0)
		tcode = b_codeof(t1code) ;
	clrscr() ;
	gotoxy(72,1) ;
	cout <<"<0>=EXIT" ;
	BOOK::display(tcode) ;
	do
	{
		gotoxy(5,13) ; clreol() ;
		cout <<"DO YOU WANT TO DELETE THIS RECORD (Y/N) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
		if (ch == '0')
			return ;
	} while (ch != 'Y' && ch != 'N') ;
	if (ch == 'N')
		return ;
	int tavail, tcopies ;
	tavail = available(tcode) ;
	tcopies = no_of_copies(tcode) ;
	if (tavail != tcopies)
	{
		gotoxy(5,15) ;
		cout <<"\7RECORD CANNOT BE DELETED. THIS BOOK IS ISSUED." ;
		getch() ;
		return ;
	}
	BOOK::delete_rec(tcode) ;
	gotoxy(5,23) ;
	cout <<"\7RECORD  DELETED" ;
	getch() ;
}

// THIS FUNCTION GIVES MEMBER CODE TO DELETE THE MEMBER
// RECORD

void WORKING :: delete_m(void)
{
	MEMBER M ;
	char m1code[5], mname[26], mphone[10], maddress[33], ch ;
	int m2code=0, mcode=0 ;
	int valid ;
	do
	{
		valid = 1 ;
		while (1)
		{
			clrscr() ;
			gotoxy(72,1) ;
			cout <<"<0>=EXIT" ;
			gotoxy(5,7) ;
			cout <<"ENTER CODE NO. OF THE MEMBER TO BE DELETED" ;
			gotoxy(5,8) ;
			cout <<"                       OR               " ;
			gotoxy(5,9) ;
			cout <<"PRESS <ENTER> FOR HELP  " ;
			gets(m1code) ;
			m2code = atoi(m1code) ;
			mcode = m2code ;
			if (m1code[0] == '0')
				return ;
			if (strlen(m1code) == 0)
				M.jot() ;
			else
				break ;
		}
		if (mcode == 0)
		{
			valid = 0 ;
			gotoxy(5,25) ;
			cout <<"\7ENTER CORRECTLY" ;
			getch() ;
		}
		if (valid && !m_found(mcode))
		{
			valid = 0 ;
			gotoxy(5,13) ;
			cout <<"\7RECORD NOT FOUND" ;
			gotoxy(5,14) ;
			cout <<"Press <ESC> to exit or any other key to continue..." ;
			ch = getch() ;
			if (ch == 27)
				return ;
		}
	} while (!valid) ;
	clrscr() ;
	gotoxy(72,1) ;
	cout <<"<0>=EXIT" ;
	MEMBER::display(mcode) ;
	do
	{
		gotoxy(5,10) ; clreol() ;
		cout <<"DO YOU WANT TO DELETE THIS RECORD (Y/N) : " ;
		ch = getche() ;
		ch = toupper(ch) ;
		if (ch == '0')
			return ;
	} while (ch != 'Y' && ch != 'N') ;
	if (ch == 'N')
		return ;
	if (issued(mcode))
	{
		gotoxy(5,15) ;
		cout <<"\7RECORD CANNOT BE DELETED. MEMBER HAS A BOOK" ;
		getch() ;
		return ;
	}
	MEMBER::del_rec(mcode) ;
	gotoxy(5,23) ;
	cout <<"\7RECORD MODIFIED" ;
	getch() ;
}

// MAIN FUNCTION CALLING INTRODUCTION AND MAIN MENU

void main(void)
{
	MENU menu ;
	menu.ma_menu() ;
}

⌨️ 快捷键说明

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