Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2341313
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:07:38

大家好,这是一个模拟提款机的程序,程序可以运行了,但是得不到我想要的答案.
如帐号为0511201013,密码为123.但是随便输入帐号和密码都可以正常取款和存款.请帮找一下原因.谢谢.
#include
#include
enum RESULT{FAIL=0,SUCC};
class ACCOUNT{
private:
unsigned long ID_No;
unsigned int password;
char name[10];
double balance;
public:
ACCOUNT(unsigned long,unsigned int,char*,double);
RESULT deposit(unsigned long,unsigned int,double);
RESULT drawing(unsigned long,unsigned int,double);
double chk_balance(unsigned long,unsigned int);
RESULT check(unsigned long,unsigned int);
};
ACCOUNT::ACCOUNT(unsigned long id,unsigned int pw,char*n,double m):ID_No(id),password(pw),balance(m)
{
strcpy(name,n);
}
RESULT ACCOUNT::deposit(unsigned long id,unsigned int pw,double m)
{
if(check(id,pw))
return FAIL;
else
{
balance+=m;
return SUCC;
}
}
RESULT ACCOUNT::drawing(unsigned long id,unsigned int pw,double m)
{
if(check(id,pw)&&balance>=m)
return FAIL;
else {
balance-=m;
return SUCC;
}
}
double ACCOUNT::chk_balance(unsigned long id,unsigned int pw)
{
if(check(id,pw))
return balance;
else
return (double)FAIL;
}
RESULT ACCOUNT::check(unsigned long id,unsigned int pw)
{
if(id==ID_No&&pw==password)
return SUCC;
else
return FAIL;
}
void main()
{
ACCOUNT TestAcc(0511201013,123,"yin",1000);
int choice;
unsigned long id;
unsigned int pw;
double m;
for(;;){
cout< cout<<"--------------"< <<"<1>存款"< <<"<2>提款"< <<"<3>查询余额"< <<"<4>结束"< <<"--------------"< <<"请选择:";
cin>>choice;
if(choice==4)
break;
cout<<"请输入帐号:";
cin>>id;
cout<<"请输入密码:";
cin>>pw;
switch(choice)
{
case 1:
cout<<"请输入存款金额:";
cin>>m;
if(TestAcc.deposit(id,pw,m))
{
cout<<"存款作业成功!您目前存款余额为:";
cout< }
else
cout<<"存款作业失败!可能是贴或密码错误..."< break;
case 2:
cout<<"请输入提款金额:";
cin>>m;
if(TestAcc.drawing(id,pw,m))
{
cout<<"提款作业成功!您目前存款余额为:";
cout< }
else
cout<<"提款作业失败!可能是贴或密码错误,或者存款不足..."< break;
case 3:
m=TestAcc.chk_balance(id,pw);
if(m)
{
cout<<"提款作业成功!您目前存款余额为:";
cout< }
else
cout<<"查询作业失败乃成功之母可能是贴或密码错误..."< break;
}
}


cout<<"谢谢使用!"<}

--------------------next---------------------

阅读(1134) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~