程序代码:
#include<iostream>
#include<string.h>
#define error 0
#define succee 1
class ACCOUNT
{
private:
unsigned long ID;
unsigned int password;
char name[20];
int ballance;
public:
ACCOUNT(unsigned long id,unsigned int pw,char *n,int a);
int cunkuan(unsigned long id,unsigned int pw,int a);
int qukuan(unsigned long id,unsigned int pw,int a);
int chaxun(unsigned long id,unsigned int pw);
int check(unsigned long id,unsigned int pw);
};
ACCOUNT::ACCOUNT(unsigned long id,unsigned int pw,char *n,int a)
{
ID=id;password=pw;
strcpy(name, n);
ballance=a;
}
int ACCOUNT::cunkuan(unsigned long id,unsigned int pw,int a)
{
if(!check(pw,id))
return error;
else
{
ballance+=a;
return succee;
cout<<"您的余额为:"<<ballance<<endl;
}
}
int ACCOUNT::qukuan(unsigned long id,unsigned int pw,int a)
{
if(!check(pw,id))
return error;
else
{if(ballance<a)
cout<<"您的余额已不足!"<<endl;
else
ballance-=a;
}
}
int ACCOUNT::chaxun(unsigned long id,unsigned int pw)
{
if(check(pw,id))
return ballance;
else
return error;
}
int ACCOUNT::check(unsigned long id,unsigned int pw)
{
if(id==ID&&pw==password)
return succee;
else
return error;
}
void main()
{
ACCOUNT A(1,1,"Angel",500);
int c;
unsigned long id;
unsigned int pw;
int a;
cout<<"欢迎使用"<<endl;
cout<<"-----------------------"<<endl;
cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
cout<<"请选择:"<<endl;
cin>>c;
getchar();
while(c!=4)
{
switch(c)
{
case 1:
cout<<"请输入账号:"<<endl;
cin>>id;
cout<<"请输入密码:"<<endl;
cin>>pw;
cout<<"请输入存款余额:"<<endl;
cin>>a;
if(A.cunkuan(id,pw,a))
{
cout<<"操作成功,您目前的余额为 "<<endl;
cout<<A.chaxun(id,pw)<<"元"<<endl;
}
else
cout<<"操作失败!"<<endl;
getchar();
break;
case 2:
cout<<"请输入账号:"<<endl;
cin>>id;
cout<<"请输入密码:"<<endl;
cin>>pw;
cout<<"请选择取款余额:\t<1>100\t<2>200\t<3>500\t<4>1000"<<endl;
cin>>a;
if(A.qukuan(id,pw,a))
{
cout<<"操作成功,您目前的余额为 "<<endl;
cout<<A.chaxun(id,pw)<<"元"<<endl;
}
else
cout<<"操作失败!"<<endl;
getchar();
break;
case 3:
cout<<"请输入账号:"<<endl;
cin>>id;
cout<<"请输入密码:"<<endl;
cin>>pw;
if(A.check(id,pw))
cout<<"您目前的余额为 "<<endl;
cout<<A.chaxun(id,pw)<<"元"<<endl;
getchar();
break;
}
cout<<"请继续选择"<<endl;
cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl;
cin>>c;
}
cout<<"谢谢使用!"<<endl;
getchar();
}
自己调试一下程序,很多程序很容易改正,你的程序基本上正确啦。