年末プロジェクト--大手銀行がまた来ました(E言語でプログラミングした日を思い出しました)
/*
* :
*Copyright(c)2013,
*All rights reserved.
* :
* :
* :2013 12 23
* :v1.0
* :
* : - -
* :
* :- -
* :
* :
*/
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include <conio.h>
using namespace std;
const string guanli="tcl";
const string guanlipassword="12345";
struct accout
{
int accoutnum; //
char name[10]; //
char indentity[18]; //
char password[7]; //
int state; //
double banlance; //
string fstate;
};
void menu();
void zhuchose();
bool password(char[]);
void openaccout();
bool indentity(char[]);
void zhuangtai(int);
void find();
int search(int);
int kahao=10000,state=1;
accout array[20000];
int size=0;
void cunkuan();
void qukuan();
void xiaohu();
bool ykahao(int);
bool zhangmiyizhi(int,char[]);
void zhuanzhang();
void gaimi();
int main()
{
menu();
return 0;
}
void menu()
{
//
char guanliname[10];
string password;
int n=0,l=0;
cout<<" +---------------------------------+"<<endl;
cout<<" | |"<<endl;
cout<<" | |"<<endl;
cout<<" | TCL |"<<endl;
cout<<" | |"<<endl;
cout<<" | |"<<endl;
cout<<" +---------------------------------+"<<endl;
cout<<" :";
while(cin>>guanliname&&guanliname!=guanli)
{
if(n<3)
{
cout<<" ! :";
n++;
}
if(n==3&&guanliname!=guanli)
{
exit(0);
}
}
if(guanliname==guanli)
{
cout<<" :";
}
while(cin>>password&&password!=guanlipassword)
{
if(l<3)
{
cout<<endl<<" ! :";
//getpass(password);
l++;
}
if(l==3&&password!=guanlipassword)
{
exit(0);
}
}
if(password==guanlipassword)
{
// ,
zhuchose();
}
}
void zhuchose()
{
int chose;
cout<<" +---------------------------------+"<<endl;
cout<<" | 1. 2. |"<<endl;
cout<<" | 3. 4. |"<<endl;
cout<<" | 5. 6. |"<<endl;
cout<<" | 7. 0. |"<<endl;
cout<<" +---------------------------------+"<<endl;
cout<<" :";
cin>>chose;
switch(chose)
{
case 1:
openaccout();
break;
case 2:
find();
break;
case 3:
cunkuan();
break;
case 4:
qukuan();
break;
case 5:
xiaohu();
break;
case 6:
gaimi();
break;
case 7:
zhuanzhang();
break;
case 0:
exit(0);
default:
cout<<" , :"<<endl;
}
}
void openaccout()
{
//
char mima1[7],mima2[7],ident[19];
bool flag=false;
cout<<" :";
while(cin>>mima1&&!password(mima1))
{
//
cout<<" ! :";
}
cout<<" :";
while(cin>>mima2&&!password(mima2))
{
cout<<" ! :";
}
if(strcmp(mima1,mima2)==0)
{
flag=true;
}
while(!flag)
{
// ,
cout<<" , :";
while(cin>>mima2&&!password(mima2))
{
cout<<" ! :";
}
if(strcmp(mima1,mima2)==0)
{
flag=true;
}
}
if(flag)
{
strcpy(array[size].password,mima1);
cout<<" !";
array[size].accoutnum=kahao++;
cout<<" :";
cin>>array[size].name;
cout<<" :";
while(cin>>ident&&!indentity(ident))
{
//
cout<<" , :";
}
strcpy(array[size].indentity,ident);
cout<<" :";
cin>>array[size].banlance;
array[size].state=state;
cout<<" !"<<endl;
size++;
zhuangtai(size-1);
zhuchose();
}
}
bool password(char a[])
{
//
bool flag=true;
int i,l;
l=strlen(a);
if(l!=6)
{
flag=false;
}
for(i=0; i<6; ++i)
{
if(!(a[i]>='0'&&a[i]<='9'))
{
flag=false;
break;
}
}
return flag;
}
bool indentity(char a[])
{
//
bool flag=true;
int i,l;
l=strlen(a);
if(l!=18)
{
flag=false;
}
if(!(a[17]>='0'&&a[17]<='9')&&a[17]!='x'&&a[17]!='X')
{
flag=false;
}
else
{
for(i=0; i<17; i++)
{
if(!(a[i]>='0'&&a[i]<='9'))
{
flag=false;
break;
}
}
}
return flag;
}
void zhuangtai(int position)
{
string fstate;
switch(array[position].state)
{
case 1:
fstate=" ";
break;
case 2:
fstate=" ";
break;
case 3:
fstate=" ";
break;
case 4:
fstate=" ";
break;
default:
break;
}
cout<<"+------------------------------------------------------------+"<<endl;
cout<<"| "<<" "<<" "<<" "<<" |"<<endl;
cout<<"| "<<array[position].accoutnum<<setw(9)<<array[position].name<<" "<<array[position].indentity<<" "<<array[position].banlance<<" "<<fstate<<" |"<<endl;
cout<<"+------------------------------------------------------------+"<<endl;
}
void find()
{
//
int fkahao;
char fmima[7];
int zhanghao=0,mim=0,position;
cout<<" :";
while(cin>>fkahao&&!ykahao(fkahao))
{
cout<<" ! :";
zhanghao++;
if(zhanghao==3)
{
exit(0);
}
}
cout<<" :";
while(cin>>fmima&&!zhangmiyizhi(fkahao,fmima))
{
cout<<" ! :";
mim++;
if(mim==3)
{
exit(0);
}
}
position=search(fkahao);
zhuangtai(position);
zhuchose();
}
void cunkuan()
{
//
int money,z,fkahao;
cout<<" :";
while(cin>>fkahao&&!ykahao(fkahao))
{
cout<<" ! :";
}
z=search(fkahao);
cout<<" :";
while(cin>>money&&money<0)
{
cout<<" , :";
}
array[z].banlance+=money;
cout<<" !"<<endl;
zhuangtai(z);
zhuchose();
}
void qukuan()
{
//
int i,money,fkahao,zhanghao=0,mim=0;
char fmima[7];
cout<<" :";
while(cin>>fkahao&&!ykahao(fkahao))
{
cout<<" ! :";
zhanghao++;
if(zhanghao==3)
{
exit(0);
}
}
cout<<" :";
while(cin>>fmima&&!zhangmiyizhi(fkahao,fmima))
{
cout<<" ! :";
mim++;
if(mim==3)
{
exit(0);
}
}
i=search(fkahao);
cout<<" :";
while(cin>>money&&money>array[i].banlance)
{
cout<<" ! :";
}
array[i].banlance-=money;
cout<<" !";
zhuangtai(i);
zhuchose();
}
void xiaohu()
{
// ,
int i,j,fkahao,zhanghao=0,mim=0;
char fmima[7],yes;
cout<<" :";
while(cin>>fkahao&&!ykahao(fkahao))
{
cout<<" ! :";
cin>>fkahao;
zhanghao++;
if(zhanghao==3)
{
exit(0);
}
}
cout<<" :";
while(cin>>fmima&&!zhangmiyizhi(fkahao,fmima))
{
cout<<" ! :";
mim++;
if(mim==3)
{
exit(0);
}
}
if(ykahao(fkahao))
{
i=search(fkahao);
cout<<" ;"<<endl;
cout<<"1. "<<endl;
cout<<"2. "<<endl;
cout<<"3. "<<endl;
cout<<"4. "<<endl;
cin>>j;
switch(j)
{
case 1:
cout<<" ?y/Y , :";
cin>>yes;
if(yes=='y'||yes=='Y')
{
array[i].state=3;
cout<<" !"<<endl;
}
break;
case 2:
cout<<" ?y/Y , :";
cin>>yes;
if(yes=='y'||yes=='Y')
{
array[i].state=1;
cout<<" !"<<endl;
}
break;
case 3:
cout<<" ?y/Y , :";
cin>>yes;
if(yes=='y'||yes=='Y')
{
array[i].state=2;
cout<<" !"<<endl;
}
break;
case 4:
cout<<" ?y/Y , :";
cin>>yes;
if(yes=='y'||yes=='Y')
{
array[i].state=4;
cout<<" !"<<endl;
}
break;
default:
cout<<" ! :";
cin>>j;
}
}
zhuangtai(i);
zhuchose();
}
void zhuanzhang()
{
//
int i=0,j=0,zhang,money,l,fkahao,zhanghao=0,mim=0;
char fmima[7];
cout<<" :";
while(cin>>fkahao&&!ykahao(fkahao))
{
cout<<" ! :";
cin>>fkahao;
zhanghao++;
if(zhanghao==3)
{
exit(0);
}
}
cout<<" :";
while(cin>>fmima&&!zhangmiyizhi(fkahao,fmima))
{
cout<<" ! :";
mim++;
if(mim==3)
{
exit(0);
}
}
l=search(fkahao);
cout<<" :";
while(cin>>zhang&&!ykahao(zhang))
{
cout<<" ! :";
cin>>zhang;
j++;
if(j==3);
{
exit(0);
}
}
cout<<" :";
while(cin>>money&&array[l].banlance<money)
{
cout<<" ! :";
cin>>money;
i++;
if(i==3)
{
exit(0);
}
}
}
bool ykahao(int fkahao)
{
//
bool flag=false;
int i;
for(i=fkahao; i>=10000; i--)
{
if(fkahao==i)
{
flag=true;
break;
}
}
return flag;
}
bool zhangmiyizhi(int fkahao,char fmima[])
{
//
int i;
bool flag=false;
i=search(fkahao);
if(strcmp(array[i].password,fmima)==0)
{
flag=true;
}
return flag;
}
void gaimi()
{
bool flag=false;
int fkahao,zhanghao=0,mim=0,i;
char fmima[7],mima1[7],mima2[7];
cout<<" :";
while(cin>>fkahao&&!ykahao(fkahao))
{
cout<<" ! :";
zhanghao++;
if(zhanghao==3)
{
exit(0);
}
}
cout<<" :";
while(cin>>fmima&&!zhangmiyizhi(fkahao,fmima))
{
cout<<" ! :";
mim++;
if(mim==3)
{
exit(0);
}
}
i=search(fkahao);
if(strcmp(array[i].password,fmima)==0)
{
cout<<" :";
while(cin>>mima1&&!password(mima1))
{
//
cout<<" ! :";
}
cout<<" :";
while(cin>>mima2&&!password(mima2))
{
cout<<" ! :";
}
if(strcmp(mima1,mima2)==0)
{
flag=true;
}
while(!flag)
{
// ,
cout<<" , :";
while(cin>>mima2&&!password(mima2))
{
cout<<" ! :";
}
if(strcmp(mima1,mima2)==0)
{
flag=true;
}
}
if(flag)
{
strcpy(array[size].password,mima1);
cout<<" !";
}
}
}
int search(int fkahao)
{
//
int position=-1,i;
for(i=0; i<size; i++)
{
if(array[i].accoutnum==fkahao)
{
position=i;
break;
}
}
return position;
}
実行結果:
心得体得:長い間書いていたが、中にはバグが修正に間に合わなかったので、まず合わせて見てみよう.