创建一个类,对银行的一般业务进行处理。
包括:开通帐户、存钱、取钱、销户、查询等功能!# include"iostream.h"# include"malloc.h"# include"string.h"# include"stdlib.h"# include"time.h"# include"windows.h"typedef struct node{char name[20];//姓名char mima[10];//密码int money;//金额int zhanghao;//账号struct node *next;}people;class bank{private:people *p;public:bank(){p=(people *)malloc(sizeof(people));p->next=NULL;}void kaihu(); //开户void cun();//存钱void qu();//取钱void xiaohu();//销户void chaxun();//查询void mulu();void xuanzhe();};void bank::kaihu(){system("cls");cout<<"\t\t\t开户"<<endl;cout<<"**************************************************"<<endl;people *m;char a[10],b[10];m=(people *)malloc(sizeof(people));srand(time(NULL));m->zhanghao=rand()%10000;memset(m->name,0,sizeof(m->name));memset(m->mima,0,sizeof(m->mima));cout<<"\n请输入姓名:";cin>>m->name;cout<<"\n请输入密码:";cin>>a;cout<<"\n请再次输入密码:";cin>>b;while(strcmp(a,b)!=0){cout<<"\n与第一次输入不符,请重新输入:";cout<<"\n请输入密码:";cin>>a;cout<<"\n请再次输入密码:";cin>>b;}strcpy(m->mima,a);m->money=100;m->next=p->next;cout<<"\n姓名:"<<m->name<<"\t账号:"<<m->zhanghao<<"\t金额:"<<m->money<<endl;p->next=m;xuanzhe();}void bank::cun(){system("cls");cout<<"\t\t\t存款"<<endl;cout<<"**************************************************"<<endl;int a,m;people *k=p;cout<<"\n请输入账号:";cin>>a;while(k!=NULL){if(k->zhanghao==a)break;else k=k->next;}if(k!=NULL){cout<<"\n姓名:"<<k->name<<"\t账号:"<<k->zhanghao<<endl;cout<<"\n请输入要存入的金额:";cin>>m;k->money=k->money+m;cout<<"\n已存入,卡中余额为:"<<k->money<<endl;}else cout<<"\n无此账户!"<<endl;xuanzhe();}void bank::qu(){system("cls");cout<<"\t\t\t取款"<<endl;cout<<"**************************************************"<<endl;char n[10];int b=2;int a,m;people *k=p;cout<<"\n请输入账号:";cin>>a;while(k!=NULL){if(k->zhanghao==a)break;else k=k->next;}if(k!=NULL){cout<<"\n请输入密码:";cin>>n;while(strcmp(k->mima,n)!=0&&b--){cout<<"\n密码错误!请重新输入,剩余次数"<<b+1<<endl;cout<<"\n请输入密码:";cin>>n;}if(b>=0){cout<<"\n姓名:"<<k->name<<"\t账号:"<<k->zhanghao<<"\t账户金额"<<k->money<<endl;cout<<"\n请输入取款金额:";cin>>m;while(m>k->money){cout<<"金额不足!";cout<<"\n请输入取款金额:";cin>>m;}k->money=k->money-m;cout<<"取款成功!账户余额:"<<k->money;}else cout<<"\n密码错误,退出!"<<endl;}else cout<<"\n无此账号!"<<endl;xuanzhe();}void bank::xiaohu(){system("cls");cout<<"\t\t\t销户"<<endl;cout<<"**************************************************"<<endl;int a,b=2,c;char n[10];memset(n,0,sizeof(n));people *k=p,*m;cout<<"\n请输入账号:"<<endl;cin>>a;while(k!=NULL){if(k->zhanghao==a)break;else{m=k;k=k->next;}}if(k!=NULL){cout<<"\n请输入密码:";cin>>n;while(strcmp(k->mima,n)!=0&&b--){cout<<"\n密码错误!请重新输入,剩余次数"<<b+1<<endl;cout<<"\n请输入密码:";cin>>n;}if(b>=0){cout<<"\n姓名:"<<k->name<<"\t账号:"<<k->zhanghao<<"\t账户金额"<<k->money<<endl;cout<<"\n确定销户请按1,返回请按2:";cin>>c;if(c==1){m->next=k->next;cout<<"\n已销户!"<<endl;xuanzhe();}if(c==2)xuanzhe();}}else xuanzhe();}void bank::chaxun(){int a,b=2,c;char n[10];memset(n,0,sizeof(n));people *k=p;cout<<"\n请输入账号:"<<endl;cin>>a;while(k!=NULL){if(k->zhanghao==a)break;else{k=k->next;}}if(k!=NULL){cout<<"\n请输入密码:";cin>>n;while(strcmp(k->mima,n)!=0&&b--){cout<<"\n密码错误!请重新输入,剩余次数"<<b+1<<endl;cout<<"\n请输入密码:";cin>>n;}if(b>=0){cout<<"\n姓名:"<<k->name<<"\t账号:"<<k->zhanghao<<"\t账户金额"<<k->money<<endl;}else cout<<"\n密码错误!退出!"<<endl;}else cout<<"\n无此账户!"<<endl;xuanzhe();}void bank::xuanzhe(){int a;cout<<"\n返回主菜单请按1,结束请按2:";cin>>a;if(a==1)mulu();if(a==2)exit(0);}void bank::mulu(){system("cls");int a;cout<<"\t\t银行系统"<<endl;cout<<"**************************************************"<<endl;cout<<"1.开户"<<endl;cout<<"2.存款"<<endl;cout<<"3.取款"<<endl;cout<<"4.销户"<<endl;cout<<"5.查询"<<endl;cout<<"**************************************************"<<endl;cout<<"\n请输入所需服务序号:";cin>>a;switch(a){case 1:kaihu();break;case 2:cun();break;case 3:qu();break;case 4:xiaohu();break;case 5:chaxun();break;}}void main(){bank b;b.mulu();}。