作者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
推 zxaustin:ㄟ 髒話刪掉吧 很難看耶 誰的版本阿 那麼沒水準 05/24 13:06
推 vialeila:是呀誰那麼沒水準...還寫那麼好害我們後面的都過不了= =+ 05/24 13:11
推 zxaustin:囧 難道企鵝臭了嗎 05/25 14:45