栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【C++】银行存取款管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【C++】银行存取款管理系统

一、 定义结构体

#include"stdio.h"
#include"iostream"
#include"string.h"
#include

using namespace std;
int num=0;
struct Login{//登录结构体,有用户名和密码 
	char username[10];
	char password[10];
}lg[100];
struct Customerinfo{
	char idcard[10];
	char cuname[20];
	char cupwd[10];
	char cuaddr[30];
	char phone[11];
	float total;
}customer[100];
struct record{
	char idcard[10];
	char date[12];
	char category[8];
	float number;
	char Handler[20];
}dwrecord[1000];

二、实现系统登录功能

int SystemLogin(char *uname,char *pword){//系统登录功能 
	FILE *fp;
	int i;
	if((fp=fopen("login.txt","r"))==NULL){
		printf("文件打开失败!n");
		return 0;
	}
	for(i=0;!feof(fp);i++){
		fscanf(fp,"%s%s",&lg[i].username,&lg[i].password);
		if((strcmp(lg[i].username,uname)==0)&&(strcmp(lg[i].password,pword)==0))
			return 1;
	}
	fclose(fp);
	return 0;
}

 三、主界面设计

int display(){//主界面 
	int m;
	printf("--欢迎使用银行存取款系统,请选择你要执行的操作--n");
	printf("------------------------------------------------n");
	printf("--   0.退出系统                  1.录入信息   --n"); 
	printf("--   2.存储                      3.取款       --n");
	printf("--   4.存款查询                  5.取款查询   --n");
	printf("--   6.显示信息                  7.删除信息   --n");
	printf("--   8.修改信息                  9.存取款统计 --n");
	printf("--   10.客户存取款排序                        --n");
	printf("------------------------------------------------n");
	printf("请输入您的选择(0-10)n");
	scanf("%d",&m);
	while(m>10||m<0){
		printf("你选择的编号有误请重新输入n");
		scanf("%d",&m);
	}
	return m;
}

 四、录入信息功能的实现

void insertcustomer(){//录入客户的账号信息 
	FILE *fp;
	int i,j,total;
	char c;
	if((fp=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
	}
	for(j=0;!feof(fp);j++){
		total++;
		fscanf(fp,"%s%s%s%s%s%f",&customer[j].idcard,&customer[j].cuname,&customer[j].cupwd,&customer[j].cuaddr,&customer[j].phone,&customer[j].total);
	}
	fp=fopen("Customerinfo.txt","a");
	for(i=0;i<100;i++){
		printf("请输入%d个人的信息",i+1);
		printf("编号:");
		scanf("%s",&customer[i].idcard);
		printf("客户姓名:");
		scanf("%s",&customer[i].cuname);
		printf("支取密码:");
		scanf("%s",&customer[i].cupwd);
		printf("客户地址:");
		scanf("%s",&customer[i].cuaddr);
		printf("客户电话:");
		scanf("%s",&customer[i].phone);
		printf("账户总金额:");
		scanf("%f",&customer[i].total);
		if((i+1)%1==0){
			getchar();
			printf("是否继续录入客户信息(y|Y)");
			scanf("%c",&c);
			if(c!='Y'&&c!='y')
				break;
		}
	}
	if(total>0)
		fprintf(fp,"n","");
	for(int j=0;j<=i;j++){
		if(j 

五、存款功能的实现 

void deposit(){//存款操作 
	system("cls");//清屏
	printf("正在进行存款操作...n");
	int i,j,flag=0,n=0,m=0;
	float k;
	FILE *fp,*ap;
	if((fp=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	printf("请输入客户编号:n");
	scanf("%s",&dwrecord[m].idcard);
	for(i=0;!feof(fp);i++){//读取用户信息,判断所要进行存款操作的账户是否存在 
		fscanf(fp,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
		if(strcmp(customer[i].idcard,dwrecord[m].idcard)==0){
			flag=1;
			n=i;
		}
	}
	if(flag){//找到相应的账户,进行存款操作 
		ap=fopen("record.txt","a");
		printf("请输入你的存款金额:n");
		scanf("%f",&k);
		customer[n].total=customer[n].total+k;//用原来的余额+存入的金额等于现有金额
		strcpy(dwrecord[n].idcard,customer[n].idcard);
		printf("请输入日期:n");
		scanf("%s",dwrecord[n].date);
		strcpy(dwrecord[n].category,"存款");
		dwrecord[n].number=k;
		printf("请输入经办人:n");
		scanf("%s",&dwrecord[n].Handler);
		fprintf(ap,"n%st%st%st%0.2ft%s",dwrecord[n].idcard,dwrecord[n].date,dwrecord[n].category,k,dwrecord[n].Handler);
		fclose(ap); 
	}
	else{
		printf("查无此人!");
		fclose(fp);
		printf("按回车键继续...");
		getchar();
		getchar();
		return;
	}
	fclose(fp);
	fp=fopen("Customerinfo.txt","w");
	for(j=0;j 

六、取款功能的实现 

void fetch(){//取款操作 
	system("cls");//清屏
	printf("正在进行取款操作...n");
	int i,j,flag=0,n=0,m=0;
	char pwd[10];
	float k;
	FILE *fp,*ap;
	if((fp=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	printf("请输入客户编号n");
	scanf("%s",&dwrecord[m].idcard);
	for(i=0;!feof(fp);i++){//读取客户信息文件,判断所要进行取款操作的账户是否存在
		fscanf(fp,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
		if(strcmp(customer[i].idcard,dwrecord[m].idcard)==0){
			flag=1;
			n=i;
		}
	}
	if(flag){//找到相应的账户,进行取款操作 
	L1:	printf("请输入密码:n");
		scanf("%s",pwd);
		if(strcmp(customer[n].cupwd,pwd)==0){
			printf("请输入你的取款金额:n");
			scanf("%f",&k);
			if(k>customer[n].total){
				printf("您的余额不足!n");
				Sleep(1000);
			}
			else{
				ap=fopen("record.txt","a");
				customer[n].total=customer[n].total-k;//用原来的余额-取出的金额等于现有金额
				strcpy(dwrecord[n].idcard,customer[n].idcard);
				printf("请输入日期:n");
				scanf("%s",dwrecord[n].date);
				strcpy(dwrecord[n].category,"取款");
				dwrecord[n].number=k;
				printf("请输入经办人:n");
				scanf("%s",&dwrecord[n].Handler);
				fprintf(ap,"%st%st%st%0.2ft%sn",dwrecord[n].idcard,dwrecord[n].date,dwrecord[n].category,k,dwrecord[n].Handler);
				fclose(ap); 
			}
		}
		else{
			num++;
			if(num<3){
				printf("密码错误,请重新输入!n");
				Sleep(2000);
				goto L1;
			}
			return;
		} 
	}
	else{
		printf("查无此人!");
		Sleep(2000);
		return;
	}
	fclose(fp);
	fp=fopen("Customerinfo.txt","w");
	for(j=0;j<=i-1;j++){
		if(j 

七、存款记录查询功能的实现 

void SearchDeposit(){//存款查询 
	char id[10],name[20];
	int i,k=0,flag=0;
	FILE *fp,*ap;
	if((fp=fopen("record.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	if((ap=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	printf("查询存款信息,请输入查询方式(1 按账号查询/2 按姓名查询):");
	scanf("%d",&k);
	while(k<1||k>2){
		printf("你输入的功能有错,请重新输入你要的查询功能(1-2)");
		scanf("%d",&k);
	}
	if(k==1){
		printf("请输入客户编号:n");
		scanf("%s",id);
		printf("编号t日期t类别t存入金额t经办人n");
		for(i=0;feof(fp);i++){//读取存款记录文件,判断所要查询的账号的存款记录。 
			fscanf(fp,"%s%s%s%f%s",&dwrecord[i].idcard,&dwrecord[i].date,&dwrecord[i].category,&dwrecord[i].number,&dwrecord[i].Handler);
			if((strcmp(dwrecord[i].idcard,id)==0)&&(strcmp(dwrecord[i].category,"存款")==0)){
				printf("%st%st%st%0.2ftt%sn",dwrecord[i].idcard,dwrecord[i].date,dwrecord[i].category,dwrecord[i].number,dwrecord[i].Handler);
				flag=1;
			}
		}
		if(!flag){
			printf("该账号不存在或没有存款记录!n");
			fclose(fp);
			printf("按回车键继续...");
			getchar();
			getchar();
			return;
		}
	}
	if(k==2){
		printf("请输入客户姓名:n");
		scanf("%s",name);
		printf("编号t日期t类别t存入金额t经办人n");
		for(i=0;feof(ap);i++){//读取客户信息文件,根据客户姓名查找相应的账号,判断所要进行查询操作的账号是否存在。 
			fscanf(ap,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
			if((strcmp(customer[i].cuname,name)==0)){
				strcpy(id,customer[i].idcard);
				break;
			}
		}
		for(i=0;feof(fp);i++){//读取客户信息文件,根据客户姓名查找相应的账号,判断所要进行查询操作的账号是否存在。 
			fscanf(fp,"%s%s%s%f%s",&dwrecord[i].idcard,&dwrecord[i].date,&dwrecord[i].category,&dwrecord[i].number,&dwrecord[i].Handler);
			if((strcmp(dwrecord[i].idcard,id)==0)&&(strcmp(dwrecord[i].category,"存款")==0)){
				printf("%st%st%st%0.2ftt%sn",dwrecord[i].idcard,dwrecord[i].date,dwrecord[i].category,dwrecord[i].number,dwrecord[i].Handler);
				flag=1;
			}
		}
		if(!flag){
			printf("该账号不存在或没有存款记录!n");
			fclose(fp);
			printf("按回车键继续...");
			getchar();
			getchar();
			return;
		}
	}
	fclose(fp);
	fclose(ap);
	printf("按回车键继续...");
	getchar();
	getchar();
}

八、取款记录查询功能的实现 

void SearchFetch(){//取款查询 
	char id[10],name[20];
	int i,k=0,flag=0;
	FILE *fp,*ap;
	if((fp=fopen("record.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	if((ap=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	printf("查询取款信息,请输入查询方式(1 按账号查询/2 按姓名查询):");
	scanf("%d",&k);
	while(k<1||k>2){
		printf("你输入的功能有错,请重新输入你要的查询功能(1-2)");
		scanf("%d",&k);
	}
	if(k==1){
		printf("请输入客户编号:n");
		scanf("%s",id);
		printf("编号t日期t类别t取出金额t经办人n");
		for(i=0;feof(fp);i++){//读取客户信息文件,判断所要进行取款查询操作的账户的取款记录 
			fscanf(fp,"%s%s%s%f%s",&dwrecord[i].idcard,&dwrecord[i].date,&dwrecord[i].category,&dwrecord[i].number,&dwrecord[i].Handler);
			if((strcmp(dwrecord[i].idcard,id)==0)&&(strcmp(dwrecord[i].category,"取款")==0)){
				printf("%st%st%st%0.2ftt%sn",dwrecord[i].idcard,dwrecord[i].date,dwrecord[i].category,dwrecord[i].number,dwrecord[i].Handler);
				flag=1;
			}
		}
		if(!flag){
			printf("该账号不存在或没有取款记录!n");
			fclose(fp);
			printf("按回车键继续...");
			getchar();
			getchar();
			return;
		}
	}
	if(k==2){
		printf("请输入客户姓名:n");
		scanf("%s",name);
		printf("编号t日期t类别t取出金额t经办人n");
		for(i=0;feof(ap);i++){//读取客户信息文件,根据客户姓名查找相应的账号,判断所要进行取款查询操作的账号是否存在。 
			fscanf(ap,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
			if((strcmp(customer[i].cuname,name)==0)){
				strcpy(id,customer[i].idcard);
				break;
			}
		}
		for(i=0;feof(fp);i++){//读取客户信息文件,根据客户姓名查找相应的账号,判断所要进行查询操作的账号是否存在。 
			fscanf(fp,"%s%s%s%f%s",&dwrecord[i].idcard,&dwrecord[i].date,&dwrecord[i].category,&dwrecord[i].number,&dwrecord[i].Handler);
			if((strcmp(dwrecord[i].idcard,id)==0)&&(strcmp(dwrecord[i].category,"取款")==0)){
				printf("%st%st%st%0.2ftt%sn",dwrecord[i].idcard,dwrecord[i].date,dwrecord[i].category,dwrecord[i].number,dwrecord[i].Handler);
				flag=1;
			}
		}
		if(!flag){
			printf("该账号不存在或没有存款记录!n");
			fclose(fp);
			printf("按回车键继续...");
			getchar();
			getchar();
			return;
		}
	}
	fclose(fp);
	fclose(ap);
	printf("按回车键继续...");
	getchar();
	getchar();
}

 九、删除信息功能的实现

void DeleteInfo(){
	FILE *fp;
	int i,j,k,flag=0,total=0;
	char id[10];
	if((fp=fopen("Customer.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	printf("请输入你要删除信息的客户编号:");
	scanf("%s",id);
	for(i=0;!feof(fp);i++){
		total++;
		fscanf(fp,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
		if(strcmp(customer[i].idcard,id)==0){
			k=i;
			flag=1;
		}
	}
	if(!flag){
		printf("你输入的客户编号有误,请正确输入你要删除的客户!n");
		fclose(fp);
		printf("按回车键继续...");
		getchar();
		getchar();
		return;
	}
	for(j=k;j 

十、显示信息功能的实现 

void ShowCuInfo(){
	int i;
	FILE *ap;
	if((ap=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	printf("编号t姓名t客户密码t客户地址t客户电话t金额n");
	for(i=0;!feof(ap);i++){//读取客户信息文件,判断所要进行操作的账号是否存在
		fscanf(ap,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
		printf("%st%st%stt%stt%st%0.2fn",customer[i].idcard,customer[i].cuname,customer[i].cupwd,customer[i].cuaddr,customer[i].phone,customer[i].total);
	}
	fclose(ap);
	printf("按回车键继续...");
	getchar();
	getchar();
}

十一、客户存取款信息排序功能的实现 

void SortCustomer(){
	FILE *ap;
	int i,j,n,k,flag=0,total=0;
	char id[10];
	if((ap=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	struct Customerinfo temp;
	printf("编号t姓名t客户密码t客户地址t客户电话t金额n");
	for(i=0;!feof(ap);i++){
		total++;
		fscanf(ap,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
	}
	for(n=0;n=n;j--){
			if(customer[j].total 

十二、修改信息功能的实现 

void UpdataInfo(){
	FILE *fp;
	int i,j,k,flag=0,total=0,n;
	char id[10],addr[30],phone[11],pwd[10];
	if((fp=fopen("Customerinfo.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	printf("请输入你要修改信息的客户编号:");
	scanf("%s",id);
	for(i=0;!feof(fp);i++){
		total++;
		fscanf(fp,"%s%s%s%s%s%f",&customer[i].idcard,&customer[i].cuname,&customer[i].cupwd,&customer[i].cuaddr,&customer[i].phone,&customer[i].total);
		if(strcmp(customer[i].idcard,id)==0){
			k=i;
			flag=1;
		}
	}
	if(!flag){
		printf("你输入的客户编号有误,请正确输入你要修改的客户!n");
		fclose(fp);
		printf("按回车键继续...");
		getchar();
		getchar();
		return;
	}
	printf("请选择你要修改的信息:(1修改密码  2修改地址  3修改电话):n");
	scanf("%d",&n);
	while(n<1||n>3){
		printf("你输入的功能有错,请重新输入你要的修改功能(1-2):");
		scanf("%d",&n);
	}
	switch(n){
		case 1:{
			printf("请输入旧密码:");
			scanf("%s",pwd);
			if(strcmp(customer[k].cupwd,pwd)==0){
				printf("请输入新密码:");
				scanf("%s",pwd);
				strcpy(customer[k].cupwd,pwd);
				printf("密码修改成功,按回车键继续...!n");
				getchar();
				getchar();
			}
			else{
				printf("旧密码不正确,按回车键继续...!n");
				getchar();
				getchar();
			}
			break;
		}
		case 2:{
			printf("请输入新地址:");
			scanf("%s",addr);
			strcpy(customer[k].cuaddr,addr);
			printf("地址修改成功,按回车键继续...!n");
			getchar();
			getchar();
			break;
		}
		case 3:{
			printf("请输入新电话号码:");
			scanf("%s",phone);
			strcpy(customer[k].phone,phone);
			printf("电话修改成功,按回车键继续...!n");
			getchar();
			getchar();
			break;
		}
	}
	fclose(fp);
	fp=fopen("Customerinfo.txt","w");
	for(j=0;j 

十三、存取款统计功能的实现 

void Statistics(){
	FILE *fp;
	int i,j,flag[100],total=0;
	char id[10],cat[6];
	system("cls");
	printf("正在统计信息...n");
	if((fp=fopen("record.txt","r"))==NULL){
		printf("文件打开失败!n");
		return;
	}
	for(i=0;!feof(fp);i++){
		fscanf(fp,"%s%s%s%f%s",&dwrecord[i].idcard,&dwrecord[i].date,&dwrecord[i].category,&dwrecord[i].Handler);
		total++;
		flag[i]=0;
	}
	for(i=0;i 

十四、主函数 

int main(int argc, char** argv) {//主函数 
	char un[10],pass[10];
	int k=0;
L:	printf("欢迎使用银行存取款系统,请输入用户名和密码登录系统!n");
	printf("用户名:");
	scanf("%s",un);
	printf("密码:");
	scanf("%s",pass);
	if(SystemLogin(un,pass)==1){
		printf("用户名和密码正确,正在登录系统...n");
		Sleep(2000);
		system("cls");
		k=display();
		while(k){
			switch(k){
				case 1:insertcustomer();break;
				case 2:deposit();		break;
				case 3:fetch();			break;
				case 4:SearchDeposit();	break;
				case 5:SearchFetch();	break;
				case 6:ShowCuInfo();	break;
				case 7:DeleteInfo();	break;
				case 8:UpdataInfo();	break;
				case 9:Statistics();	break;
				case 10:SortCustomer();	break;
			}
			system("cls");
			k=display();
		}
	}
	else{
		printf("用户名或密码错误,请重新输入!n");
		Sleep(2000);
		system("cls");
		num++;
		if(num<3)
			goto L;
	}
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/971953.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号