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

📄 a project of bank.cpp

📁 For about Banking system. I copy from CodeProject.com.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		clear(5,23) ;
		gotoxy(5,23) ;
		cout <<"ENTER ADDRESS OF THE PERSON" ;
		valid = 1 ;
		gotoxy(15,11) ;
		gets(t_address) ;
		strupr(t_address) ;
		if (t_address[0] == '0')
			return ;
		if (strlen(t_address) == 0 || strlen(t_address) > 55)
		{
			valid = 0 ;
			gotoxy(5,23) ;
			cprintf("\7SHOULD NOT BLANK OR GREATER THAN 55") ;
			getch() ;
		}
	} while (!valid) ;
	do
	{
		char vari[30] ;
		clear(31,12) ;
		clear(5,23) ;
		gotoxy(5,23) ;
		cout <<"ENTER NAME OF THE VERIFYING PERSON" ;
		valid = 1 ;
		gotoxy(31,12) ;
		gets(vari) ;
		strupr(vari) ;
		if (vari[0] == '0')
			return ;
		if (strlen(vari) == 0 || strlen(vari) > 25)
		{
			valid = 0 ;
			gotoxy(5,23) ;
			cprintf("\7SHOULD NOT BLANK OR GREATER THAN 25") ;
			getch() ;
		}
	} while (!valid) ;
	do
	{
		clear(23,14) ;
		clear(5,23) ;
		gotoxy(5,23) ;
		cout <<"ENTER INITIAL AMOUNT TO BE DEPOSIT" ;
		valid = 1 ;
		gotoxy(23,14) ;
		gets(t) ;
		t_bal = atof(t) ;
		t_balance = t_bal ;
		if (t[0] == '0')
			return ;
		if (t_balance < 500)
		{
			valid = 0 ;
			gotoxy(5,23) ;
			cprintf("\7SHOULD NOT LESS THAN 500          ") ;
			getch() ;
		}
	} while (!valid) ;
	clear(5,23) ;
	do
	{
		clear(5,17) ;
		valid = 1 ;
		gotoxy(5,17) ;
		cout <<"Do you want to save the record (y/n) : " ;
		ch = getche() ;
		if (ch == '0')
			return ;
		ch = toupper(ch) ;
	} while (ch != 'N' && ch != 'Y') ;
	if (ch == 'N')
		return ;
	float t_amount, t_interest ;
	t_amount = t_balance ;
	t_interest = 0.0 ;
	char t_tran, t_type[10] ;
	t_tran = 'D' ;
	strcpy(t_type,"INITIAL") ;
	ini.add_to_file(t_accno,t_name,t_address,t_balance) ;
	add_to_file(t_accno,d1,m1,y1,t_tran,t_type,t_interest,t_amount,t_balance) ;
}


//**********************************************************
// THIS FUNCTION DRAWS THE BOX FOR DISPLAYING RECORD FROM
// FILE BANKING.DAT
//**********************************************************

void account :: box_for_display(int t_accno)
{
	shape s ;
	s.box(2,1,79,25,218) ;
	s.line_hor(3,78,4,196) ;
	s.line_hor(3,78,6,196) ;
	s.line_hor(3,78,23,196) ;
	textbackground(BLUE) ;
	gotoxy(3,5) ;
	for (int i=1; i<=76; i++) cprintf(" ") ;
	textbackground(BLUE) ;
	textcolor(RED) ; textbackground(BLUE) ;
	gotoxy(4,5) ;
	cprintf("DATE        PARTICULAR    DEPOSIT     WITHDRAW    INTEREST    BALANCE") ;
	textcolor(YELLOW) ; textbackground(BLACK) ;
	int d1, m1, y1 ;
	struct date d;
	getdate(&d);
	d1 = d.da_day ;
	m1 = d.da_mon ;
	y1 = d.da_year ;
	gotoxy(63,2) ;
	cout <<"Date: " <<d1 <<"/" <<m1 <<"/" <<y1 ;
	gotoxy(4,2) ;
	cout <<"Account no. " <<t_accno ;
	initial ini ;
	char t_name[30] ;
	strcpy(t_name,ini.return_name(t_accno)) ;
	char t_address[60] ;
	strcpy(t_address,ini.return_address(t_accno)) ;
	gotoxy(25,2) ;
	cout <<t_name ;
	gotoxy(25,3) ;
	cout <<t_address ;
}


//**********************************************************
// THIS FUNCTION DISPLAY RECORD FROM THE FILE BANKING.DAT
//**********************************************************

void account :: display_account(void)
{
	clrscr() ;
	char t_acc[10] ;
	int t, t_accno ;
	gotoxy(71,1) ;
	cout <<"<0>=Exit" ;
	gotoxy(5,5) ;
	cout <<"Enter the account no. " ;
	gets(t_acc) ;
	t = atoi(t_acc) ;
	t_accno = t ;
	if (t_accno == 0)
		return ;
	clrscr() ;
	initial ini ;
/*	if (!ini.found_account(t_accno))
	{
		gotoxy(5,5) ;
		cout <<"\7Account not found" ;
		getch() ;
		return ;
	} */
	box_for_display(t_accno) ;
	int row=7, flag ;
	fstream file ;
	file.open("BANKING.DAT", ios::in) ;
	while (file.read((char *) this, sizeof(account)))
	{
		if (accno == t_accno)
		{
			flag = 0 ;
			delay(10) ;
			gotoxy(4,row) ;
			cout <<dd <<"/" <<mm <<"/" <<yy ;
			gotoxy(16,row) ;
			cout <<type ;
			if (tran == 'D')
				gotoxy(30,row) ;
			else
				gotoxy(42,row) ;
			cout <<amount ;
			gotoxy(56,row) ;
			cout <<interest;
			gotoxy(66,row) ;
			cout <<balance ;
			row++ ;
			if (row == 23)
			{
				flag = 1 ;
				row = 7 ;
				gotoxy(4,24) ;
				cout <<"Press any key to continue..." ;
				getch() ;
				clrscr() ;
				box_for_display(t_accno) ;
			}
		}
	}
	file.close() ;
	if (!flag)
	{
		gotoxy(4,24) ;
		cout <<"Press any key to continue..." ;
		getch() ;
	}

}


//**********************************************************
// THIS FUNCTION RETURNS THE DIFFERENCE BETWEEN 2 DATES.
//**********************************************************

int account :: no_of_days(int d1, int m1, int y1, int d2, int m2, int y2)
{
	static int month[] = {31,28,31,30,31,30,31,31,30,31,30,31} ;
	int days = 0 ;
	while (d1 != d2 || m1 != m2 || y1 != y2)
	{
		days++ ;
		d1++ ;
		if (d1 > month[m1-1])
		{
			d1 = 1 ;
			m1++ ;
		}
		if (m1 > 12)
		{
			m1 = 1 ;
			y1++ ;
		}
	}
	return days ;
}


//**********************************************************
// THIS FUNCTION CALCULATES INTEREST.
//**********************************************************

float account :: calculate_interest(int t_accno, float t_balance)
{
	fstream file ;
	file.open("BANKING.DAT", ios::in) ;
	file.seekg(0,ios::beg) ;
	int d1, m1, y1, days ;
	while (file.read((char *) this, sizeof(account)))
	{
		if (accno == t_accno)
		{
			d1 = dd ;
			m1 = mm ;
			y1 = yy ;
			break ;
		}
	}
	int d2, m2, y2 ;
	struct date d;
	getdate(&d);
	d2 = d.da_day ;
	m2 = d.da_mon ;
	y2 = d.da_year ;
	float t_interest=0.0 ;
	if ((y2<y1) || (y2==y1 && m2<m1) || (y2==y1 && m2==m1 && d2<d1))
		return t_interest ;
	days = no_of_days(d1,m1,y1,d2,m2,y2) ;
	int months=0 ;
	if (days >= 30)
	{
		months = days/30 ;
		t_interest = ((t_balance*2)/100) * months ;
	}
	file.close() ;
	return t_interest ;
}


//**********************************************************
// THIS FUNCTION MAKES TRANSACTIONS (DEPOSIT/WITHDRAW).
//**********************************************************

void account :: transaction(void)
{
	clrscr() ;
	char t_acc[10] ;
	int t, t_accno, valid ;
	gotoxy(71,1) ;
	cout <<"<0>=Exit" ;
	gotoxy(5,5) ;
	cout <<"Enter the account no. " ;
	gets(t_acc) ;
	t = atoi(t_acc) ;
	t_accno = t ;
	if (t_accno == 0)
		return ;
	clrscr() ;
	initial ini ;
	if (!ini.found_account(t_accno))
	{
		gotoxy(5,5) ;
		cout <<"\7Account not found" ;
		getch() ;
		return ;
	}
	shape s ;
	s.box(2,2,79,24,218) ;
	s.line_hor(3,78,4,196) ;
	s.line_hor(3,78,22,196) ;
	gotoxy(71,1) ;
	cout <<"<0>=Exit" ;
	textbackground(BLUE) ;
	gotoxy(3,3) ;
	for (int i=1; i<=76; i++) cprintf(" ") ;
	textbackground(BLACK) ;
	textcolor(RED+BLINK) ; textbackground(BLUE) ;
	gotoxy(29,3) ;
	cprintf("TRANSACTION IN ACCOUNT") ;
	textcolor(YELLOW) ; textbackground(BLACK) ;
	int d1, m1, y1 ;
	struct date d;
	getdate(&d);
	d1 = d.da_day ;
	m1 = d.da_mon ;
	y1 = d.da_year ;
	gotoxy(5,6) ;
	cout <<"Date : "<<d1 <<"/" <<m1 <<"/" <<y1 ;
	gotoxy(5,8) ;
	cout <<"Account no. # " <<t_accno ;
	char t_name[30] ;
	char t_address[60] ;
	float t_balance ;
	strcpy(t_name,ini.return_name(t_accno)) ;
	strcpy(t_address,ini.return_address(t_accno)) ;
	t_balance = ini.give_balance(t_accno) ;
	s.box(25,10,75,13,218) ;
	gotoxy(27,11) ;
	cout <<"Name   : " <<t_name ;
	gotoxy(27,12) ;
	cout <<"Address: " <<t_address ;
	gotoxy(5,15) ;
	cout <<"Last Balance : Rs." <<t_balance ;
	char  t_tran, t_type[10], tm[10] ;
	float t_amount, t_amt ;
	do
	{
		clear(5,18) ;
		valid = 1 ;
		gotoxy(5,18) ;
		cout <<"Deposit or Withdraw (D/W) : " ;
		t_tran = getche() ;
		if (t_tran == '0')
			return ;
		t_tran = toupper(t_tran) ;
	} while (t_tran != 'D' && t_tran != 'W') ;
	do
	{
		clear(5,19) ;
		clear(5,23) ;
		gotoxy(5,23) ;
		cout <<"ENTER TRANSACTION BY CASH OR CHEQUE" ;
		valid = 1 ;
		gotoxy(5,19) ;
		cout <<"(Cash/Cheque) : " ;
		gets(t_type) ;
		strupr(t_type) ;
		if (t_type[0] == '0')
			return ;
		if (strcmp(t_type,"CASH") && strcmp(t_type,"CHEQUE"))
		{
			valid = 0 ;
			gotoxy(5,23) ;
			cprintf("\7ENTER CORRECTLY                       ") ;
			getch() ;
		}
	} while (!valid) ;
	do
	{
		clear(5,21) ;
		clear(5,23) ;
		gotoxy(5,23) ;
		cout <<"ENTER AMOUNT FOR TRANSACTION" ;
		valid = 1 ;
		gotoxy(5,21) ;
		cout <<"Amount : Rs." ;
		gets(tm) ;
		t_amt = atof(tm) ;
		t_amount = t_amt ;
		if (tm[0] == '0')
			return ;
		if ((t_tran == 'W' && t_amount > t_balance) || (t_amount < 1))
		{
			valid = 0 ;
			gotoxy(5,23) ;
			cprintf("\7INVALID DATA ENTERED               ") ;
			getch() ;
		}
	} while (!valid) ;
	char ch ;
	clear(5,23) ;
	do
	{
		clear(40,20) ;
		valid = 1 ;
		gotoxy(40,20) ;
		cout <<"Save transaction (y/n): " ;
		ch = getche() ;
		if (ch == '0')
			return ;
		ch = toupper(ch) ;
	} while (ch != 'N' && ch != 'Y') ;
	if (ch == 'N')
		return ;
	float t_interest ;
	t_interest = calculate_interest(t_accno,t_balance) ;
	if (t_tran == 'D')
		t_balance = t_balance + t_amount + t_interest ;
	else
		t_balance = (t_balance - t_amount) + t_interest ;
	ini.update_balance(t_accno,t_balance) ;
	add_to_file(t_accno,d1,m1,y1,t_tran,t_type,t_interest,t_amount,t_balance) ;
}


//**********************************************************
// THIS FUNCTION CLOSE THE ACCOUNT (DELETE ACCOUNT).
//**********************************************************

void account :: close_account(void)
{
	clrscr() ;
	char t_acc[10] ;
	int t, t_accno ;
	gotoxy(71,1) ;
	cout <<"<0>=Exit" ;
	gotoxy(5,5) ;
	cout <<"Enter the account no. " ;
	gets(t_acc) ;
	t = atoi(t_acc) ;
	t_accno = t ;
	if (t_accno == 0)
		return ;
	clrscr() ;
	initial ini ;
	if (!ini.found_account(t_accno))
	{
		gotoxy(5,5) ;
		cout <<"\7Account not found" ;
		getch() ;
		return ;
	}
	shape s ;
	s.box(2,2,79,24,218) ;
	s.line_hor(3,78,4,196) ;
	s.line_hor(3,78,22,196) ;
	gotoxy(71,1) ;
	cout <<"<0>=Exit" ;
	textbackground(BLUE) ;
	gotoxy(3,3) ;
	for (int i=1; i<=76; i++) cprintf(" ") ;
	textbackground(BLACK) ;
	textcolor(RED+BLINK) ; textbackground(BLUE) ;
	gotoxy(30,3) ;
	cprintf("CLOSE ACCOUNT SCREEN") ;
	textcolor(YELLOW) ; textbackground(BLACK) ;
	int d1, m1, y1 ;
	struct date d;
	getdate(&d);
	d1 = d.da_day ;
	m1 = d.da_mon ;
	y1 = d.da_year ;
	gotoxy(62,5) ;
	cout <<"Date: "<<d1 <<"/" <<m1 <<"/" <<y1 ;
	char ch ;
	ini.display(t_accno) ;
	do
	{
		clear(5,15) ;
		gotoxy(5,15) ;
		cout <<"Close this account (y/n): " ;
		ch = getche() ;
		if (ch == '0')
			return ;
		ch = toupper(ch) ;
	} while (ch != 'N' && ch != 'Y') ;
	if (ch == 'N')
		return ;
	ini.delete_account(t_accno) ;
	delete_account(t_accno) ;
	gotoxy(5,20) ;
	cout <<"\7Record Deleted" ;
	gotoxy(5,23) ;
	cout <<"Press any key to continue..." ;
	getch() ;
}


//************************************************************
// THIS IS MAIN FUNCTION CALLING HELP AND MAIN MENU FUNCTIONS
//************************************************************


void main(void)
{
	control c ;
	c.help();
	c.main_menu() ;
}

⌨️ 快捷键说明

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