作者loshihyen (瘦瘦)
看板ESOE-94
标题[公告] 计程实习11
时间Wed May 24 09:22:19 2006
#include<iostream>
#include<string.h>
using namespace std;
class Account{
private:
bool state;
int error;
double amount;
char name[20];
int password;
public:
Account(){
char cool[20]="admin";
strcpy(name,cool);
password=123;
amount=0;
error=0;
state=true;
}
Account(char* iname,int ipsw,double imoney,bool istate,int ierror){
strcpy(name,iname);
password=ipsw;
amount=imoney;
error=ierror;
state=istate;
}
void withdraw(double imoney){
if(check()){
if(amount>=imoney){
amount-=imoney;
cout<<"领出NT "<<imoney<<endl;
}else{
cout<<"余额不足 呼叫保安!"<<endl;
}
}
}
void deposit(double imoney){
if(check()){
amount+=imoney;
cout<<"存入NT "<<imoney<<endl;
}
}
void query(){
if(check()){
cout<<"剩下NT "<<amount<<endl;
}
}
void changepassword(){
if(check()){
int ipsw;
cout<<"输入新密码:";
cin>>ipsw;
password=ipsw;
cout<<"更换密码成功!"<<endl;
}
}
int check(){
if(state==true){
int ipsw;
for(;state==true;){
cout<<"输入密码:";
cin>>ipsw;
if(ipsw!=password){
error++;
if(error>=3){
cout<<"输入错误超过3次 掰掰~"<<endl;
state=false;
}else{
cout<<"输入错误!!"<<endl;
}
return 0;
}
error=0;
return 1;
}
}else{
cout<<"此帐号已冻结,请电客服 凸"<<endl;
return 0;
}
}
};
void main(){
char name[20];
int psw;
double amount;
int error;
cout<<"输入帐户名:";
cin>>name;
cout<<"输入密码:";
cin>>psw;
cout<<"输入金额:";
cin>>amount;
cout<<"错误次数?";
cin>>error;
Account ac1;
Account ac2(name,psw,amount,true,error);
int y;
double m;
for(;;){
cout<<"选择动作:(1.提款/2.存款/3.查询余额/4.改变密码)";
cin>>y;
switch(y){
case 1:
cout<<"提款金额:";
cin>>m;
ac2.withdraw(m);
break;
case 2:
cout<<"存款金额:";
cin>>m;
ac2.deposit(m);
break;
case 3:
ac2.query();
break;
case 4:
ac2.changepassword();
break;
}
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.40.225
1F:推 zxaustin:ㄟ 脏话删掉吧 很难看耶 谁的版本阿 那麽没水准 05/24 13:06
2F:推 vialeila:是呀谁那麽没水准...还写那麽好害我们後面的都过不了= =+ 05/24 13:11
3F:推 zxaustin:囧 难道企鹅臭了吗 05/25 14:45