?? function.h
字號(hào):
#include "account.h"
bool checkpassword1(int state); // 核對(duì)密碼
bool checkpassword2(); //////////////////////////////////////////////
bool passwordlen(char pwd[]); //察看查看密碼的長(zhǎng)度
void changepassword(); // 修改密碼
void fetchmoney(); // 取款
void depositmoney(); //存款
void lookaccount(); //查看一個(gè)帳戶信息
void information1(float money1); //查詢createaccount的信息
void exitsystem(); // 退出系統(tǒng)
void createaccount(); //創(chuàng)建一個(gè)用戶//寫(xiě)道文件就要的了
int lookallaccount(); //查看所以的帳戶信息
int lookaccount_note(char num[]); //查看一個(gè)帳戶日志
int lookallaccount_note(); //查看所以的帳戶日志
void functionshow1(); // 功能界面1
void functionshow2(); // 功能界面2
void welcome(); // 登陸界面
void sleep1(int time1); // 如果出現(xiàn)可疑才操作那么計(jì)算機(jī)睡覺(jué)三分鐘
int file1(int state); //從account文件里面得到信息并,驗(yàn)證用戶的信息
int file2 (); //驗(yàn)證管理員
int file3(); //每操作完成后用來(lái)保存數(shù)據(jù),,,,,;
int create_note(); //創(chuàng)建日志文件
int add_note(char information1[],char method1[],float money1); //添加日志消息
void exitsystem()
{
cout<<endl<<"感謝你對(duì)我的支持,歡迎下次光臨!"<<endl;
cout<<"請(qǐng)取卡……"<<endl;
exit(0);
}
void sleep1(int time1)// 如果出現(xiàn)可疑才操作那么計(jì)算機(jī)睡覺(jué)三分鐘
{
time_t a,b;
a=time(NULL);
while(b-a<=time1)
{b=time(NULL);}
}
bool passwordlen(char pwd[])//察看查看密碼的長(zhǎng)度
{
if(strlen(pwd)==6)return true ;
else return false;
}
/*bool checkpassword2()
{
char pwd1[7];int time=0;
for(;;)
{ cout<<"請(qǐng)輸入密碼:";
cin>>pwd1;
if(passwordlen(pwd1)) break;
else cout<<"密碼不足六位"<<endl;
time++;
if(time>=3) {cout<<"三次沒(méi)有成功計(jì)算機(jī)休眠三分鐘:"<<endl;getchar();sleep1(1800);}
}
if(strcmp(pwd1,system1.password)==0)
return true;
else return false;
}*/
bool checkpassword1(int state)//state=0 表示核對(duì)account的密碼,為1表示核對(duì)system的密碼
{
char pwd[7];
int time=0;
for(;;)
{
cout<<"請(qǐng)輸入密碼:";
cin>>pwd;
if(passwordlen(pwd)) break;
else cout<<"密碼不足六位"<<endl;
time++;
if(time>=3) {cout<<"三次沒(méi)有成功計(jì)算機(jī)休眠三分鐘:"<<endl;getchar();sleep1(1800);}
}
if(state==0)
{
if(strcmp(pwd,account1.password)==0)
return true;
else return false;
}
else
{
if(strcmp(pwd,system1.password)==0)
return true;
else return false;
}
}
void welcome()
{
char c;
cout<<endl<<endl;
cout<<"####################################################"<<endl;
cout<<"## 歡迎來(lái)到我的ATM銀行! ##"<<endl;
cout<<"####################################################"<<endl;
cout<<endl<<endl;
cout<<"1.管理員。"<<endl;
cout<<"2.用戶。"<<endl;
cout<<"0.退出。"<<endl;
cout<<"<0-2>"<<endl;
cin>>c;
while(c!='1'&& c!='2'&& c!='3')
{
cout<<"請(qǐng)輸入合法的數(shù)據(jù)〈0到2〉"<<endl;
cin>>c;
}
switch(c)
{
case '1' :
file2 ();checkpassword1(1);functionshow1();break;
case '2':
if(file1(0))
welcome();functionshow2();break;
case '0':
exitsystem();
}
}
void functionshow2()
{
char c;
cout<<"1.存款業(yè)務(wù)"<<endl;
cout<<"2.取款業(yè)務(wù)"<<endl;
cout<<"3.查詢余額"<<endl;
cout<<"4.修改密碼"<<endl;
cout<<"0.退出"<<endl;
cout<<"<0-4>"<<endl;
cin>>c;
while(c!='1' && c!='2' && c!='3' && c!='4' && c!='0')
{
cout<<"請(qǐng)輸入合法的數(shù)據(jù)."<<endl;
cin>>c;
}
switch (c)
{
case '1':
depositmoney();break;
case '2':
fetchmoney(); break;
case '3':
information1(0.0);functionshow2(); break;
case '4':
changepassword();break;
case '0':
welcome();
}
}
void changepassword()
{
int times=0;
float money1=0.0;
char pwd1[7];
char pwd2[7];
char c;
for(;;)
{
cout<<"請(qǐng)輸入你的老密碼:"<<endl;
cin>>pwd1;
if(strcmp(pwd1,account1.password)==0)
{
for(;;)
{
cout<<"請(qǐng)輸入新的密碼:"<<endl;
cin>>pwd1;
cout<<"請(qǐng)確認(rèn)你的密碼:"<<endl;
cin>>pwd2;
if(strcmp(pwd1,pwd2)==0 && strlen(pwd1)==6 && strlen(pwd2)==6)//驗(yàn)證密碼的合法性
{strcpy(pwd2,account1.password);
strcpy(account1.password,pwd1);
if(file3() )
{ char information[80];char method[20];
strcpy(method,"修改密碼:" );
strcpy(information,"老密碼 ");
strcat(information,pwd2);
strcat(information,"修改為 ");
strcat(information,pwd1);
if(add_note(information,method,money1))//保存操作記錄
{cout<<"操作成功:"<<endl<<"請(qǐng)牢記你的密碼:"<<endl;}
else {cout<<"不能夠保存東東:"<<endl;cout<<"計(jì)算機(jī)錯(cuò)誤!"<<endl;}
getchar();
}functionshow2();}
else
{
if(strlen(pwd1)!=6) cout<<"密碼要6位<0.放棄>,<enter,繼續(xù)>"<<endl;
else
cout<<"倆次輸入的密碼不同<0.放棄>,<enter,繼續(xù)>:"<<endl;
flushall();
c=getchar();
if(c=='0') functionshow2();
else break;
}
}
}
else
{times++;
if(times>=3)
{cout<<"對(duì)不起,三次沒(méi)有操作成功,計(jì)算機(jī)休眠3分鐘"<<endl;sleep1(1800);functionshow2();}
cout<<"非法:<0.返回>,<enter.繼續(xù)>"<<endl;
c=getchar();
if(c=='0') functionshow2();
}
}
}
/*void information()
{char c;
cout<<"**********************************"<<endl;
cout<<"*"<<endl;
cout<<"* 用戶姓名:"<<account1.name<<endl;
cout<<"* 卡號(hào): "<<account1.num<<endl;
cout<<"* 余額: "<<account1.money<<endl;
cout<<"**********************************"<<endl;
cout<<endl<<endl;
cout<<"任意鍵退出:"<<endl;
c=getchar();
functionshow2();
}*/
void information1(float money1)
{
char c;
time_t tm=time(NULL);
cout<<"**********************************"<<endl;
cout<<"*"<<endl;
cout<<"* 卡號(hào): "<<account1.num<<endl;
cout<<"* 用戶姓名:"<<account1.name<<endl;
cout<<"* 余額: "<<account1.money<<endl;
if(money1!=0.0)//沒(méi)有money的操作那么就不打印交易金額
{cout<<"* 交易金額:"<<money1<<endl;
cout<<"* 交易時(shí)間:"<<ctime(&tm)<<endl;}
cout<<"**********************************"<<endl;
cout<<endl<<endl;
c=getchar();
}
void depositmoney() //存款
{
float money1=0.0;
char c;
char information[80];
char method[20];
while(1)
{
cout<<"請(qǐng)輸入你的金額:";
cout<<"<輸入0取消>";
cout<<"操作金額是:";
flushall();
cin>>money1;
while(1)
{
if(money1<0.0)
{
cout<<money1<<"小于0:"<<endl<<"請(qǐng)輸入合法的數(shù)據(jù):"<<endl;
cout<<":"<<endl;
cin>>money1;
}
else
{
strcpy(information,"存款操作 ");
strcpy(method,"存款: ");
account1.money+=money1;
if(file3()&&add_note(information,method,money1))//保存日志消息
cout<<"操作完成:"<<endl;
else cout<<"不能夠保存,和管理員聯(lián)系"<<endl;
cout<<"是否要求打印交易單?"<<endl;
cout<<"<0.back:><enter.打印>"<<endl;
c=getchar();
if(c!='0') information1(money1);
functionshow2();
}
}
}
}
void fetchmoney()
{
char information[80];
char method[20];
float mn;
char c;
for(;;)
{
while(1)
{
cout<<"<輸入0取消>";
cout<<"操作金額:";
cin>>mn;
if (mn<0.0) cout<<"輸入錯(cuò)誤,重新輸入"<<endl;
else if(mn>account1.money) cout<<"余額不足!"<<endl;
else break;
}
strcpy(information,"取款操作: ");
strcpy(method,"取款:");
account1.money=account1.money-mn;
if(file3()&&add_note(information,method,mn))//保存日志消息
cout<<"操作成功"<<endl<<"要打印交易單嗎?<0.exit>,<enter,打印>"<<endl;
else cout<<"不能夠保存,和管理員聯(lián)系"<<endl;
flushall();
c=getchar();
if (c=='0') functionshow2();
information1(mn);
}
}
void functionshow1()
{
char num[20];
char ch;
char c;
cout<<"1.創(chuàng)建一個(gè)用戶。"<<endl;
cout<<"2.查看一個(gè)帳戶。"<<endl;
cout<<"3.查看所有的帳戶。"<<endl;
cout<<"4.查看一個(gè)日志:"<<endl;
cout<<"5.查看所以日志:"<<endl;
cout<<"0.返回。"<<endl;
cin>>c;
while(c!='1' && c!='2' && c!='3' && c!='4' && c!='0' && c!='5')
{
cout<<" 請(qǐng)輸入合法的數(shù)據(jù)!<0-5>"<<endl;
cin>>c;
}
switch(c)
{
case '1':
createaccount();break;
case '2':
lookaccount();break;
case '3':
if(lookallaccount()) functionshow1();break;
case '4':
if(!file1(1))
{
if(lookaccount_note(account1.num))
while(1)
{
cout<<"<0退出><enter,繼續(xù)>";
flushall();
ch=getchar();
if(ch=='0')functionshow1();
else
{cout<<"卡號(hào):"<<endl;cin>>num;lookaccount_note(num);}
}
}
else functionshow1(); break;
case '5':
lookallaccount_note();functionshow1();
case '0':
welcome();
}
}
void lookaccount()
{
char card[20];
char c1,c;
FILE *fp;
if((fp=fopen("account","rb"))==0)
{cout<<"can't open this file! any key to continue ";cin>>c;exit(0);}
for(;;)
{
rewind(fp);
cout<<"請(qǐng)輸入要查詢的帳戶號(hào)碼:"<<endl;
cin>>card;
for(;!feof(fp);)
{
fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);
//從文件中得到用戶信息,如果和卡號(hào)相同,就打印出來(lái)
if(strcmp(card,account1.num)==0)
{
cout<<"ID號(hào)碼:"<<account1.num<<endl;
cout<<"用戶名:"<<account1.name<<endl;
cout<<"余額: "<<account1.money<<endl;
cout<<"<0.退出>?<enter,繼續(xù)>"<<endl;
flushall();
c=getchar();
if (c=='0') {fclose(fp);functionshow1();}
else {rewind(fp);break;}
}
}
if(feof(fp))
{cout<<"沒(méi)有這個(gè)帳戶!!!";
cout<<"<0.退出>?<enter,繼續(xù)>"<<endl;
cout<<endl;
flushall();
c1=getchar();
if (c1=='0') {fclose(fp);functionshow1();}
}
}
}
int lookallaccount() //查詢所以的帳戶信息
{
char c;
int i=0;//用戶個(gè)數(shù)
float money1=0.0;//為information 著準(zhǔn)備
FILE *fp;
if((fp=fopen("account","rb"))==NULL)
{cout<<"can't open this file "<<endl;cin>>c;functionshow1();}
for(;!feof(fp);i++)
{
fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);
cout<<"ID號(hào)碼:"<<account1.num<<" ";
cout<<"用戶名:"<<account1.name<<" ";
cout<<"余額: "<<account1.money<<" ";
money1+=account1.money;
cout<<endl;
}
cout<<"一共有"<<i<<"個(gè)用戶"<<endl;
cout<<"總金額、為:"<<money1<<endl;
cout<<"<0.eixt>"<<endl;
cin>>c;
functionshow1();
return 1;
}
void createaccount() //添加一個(gè)用戶,把信息加到account文件的末尾,,同時(shí)創(chuàng)建日志文件
{
int i;
int j;
float money1,money2;
char c;
FILE *fp;//account 文件
FILE *fp0;//account.bak文件
char pwd1[7],pwd2[7];
money1=0.0;//為information 著準(zhǔn)備
if((fp0=fopen("account.bak","ab+"))==NULL)
{cout<<"can't opent this file account.bak!"<<endl;getchar();functionshow1();}
if((fp=fopen("account","ab+"))==NULL)
{cout<<"can't open this file "<<endl;getchar();functionshow1();}
else
{
for(;!feof(fp);)
{fscanf(fp,"%s %f %s %s ",account1.num,&account1.money,account1.name,account1.password);}
}
i=atoi(account1.num);
i++;
itoa(i,account1.num,10);
cout<<"輸入用戶名:"<<endl;
cin>>account1.name;//獲得最后的一個(gè)id號(hào)碼,為添加id著準(zhǔn)備
for(;;)
{
cout<<"輸入密碼:";
cin>>pwd1;
cout<<"確認(rèn)密碼:";
cin>>pwd2;
cout<<"現(xiàn)在要存錢(qián)?<0.否>,<enter,是>"<<endl;
c=getchar();
if(c!='0')
while(1)
{
cout<<"請(qǐng)輸入你要操作的金額:"<<endl;
cin>>money1;
cout<<"你要存入"<<money1<<"元.請(qǐng)確認(rèn):"<<endl;
cin>>money2;
if(money1!=money2) {cout<<"倆次輸入不同重新來(lái)."<<endl;getchar();}
else {account1.money=money1;break;}
}
if(strcmp(pwd1,pwd2)==0 && strlen(pwd1)==6 && strlen(pwd2)==6)//驗(yàn)證密碼
{ //如果密碼正確,打印到文件之中
strcpy(account1.password,pwd2);
fprintf(fp,"%s %f %s %s ",account1.num,account1.money,account1.name,account1.password);
fprintf(fp0,"%s %f %s %s ",account1.num,account1.money,account1.name,account1.password);
if(create_note()) //創(chuàng)建note
{fclose(fp);fclose(fp0);information1(money1);}
flushall();
functionshow1();
}
else
{ if (strlen(pwd1)!=6) cout<<"密碼要六位"<<endl;
else cout<<"密碼確認(rèn)錯(cuò)誤重新來(lái)!"<<endl;
cout<<"<0.退出>"<<endl;
flushall();c=getchar();
if(c=='0') functionshow1();
}
}
}
int lookaccount_note(char num[])
{
char information[80];
float money1;
FILE * fp;
time_t tm;
if((fp=fopen(num,"rb"))==NULL)
{cout<<"can't open this file "<<endl;getchar();return 0;}
for(;!feof(fp);)
{
fscanf(fp,"%s %f %d\n",information,&money1,&tm);
cout<<information<<" "<<money1<<" "<<ctime(&tm)<<endl;//tiem 是用long 來(lái)保存的所以讀出來(lái)了用ctime(&tm);
}
fclose(fp);
cout<<"any keys to continue !"<<endl;
getchar();
return 1;
}
int lookallaccount_note()
{
account account2;//臨時(shí)的變量,保證全局變量不受影響
char num[20];
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -