程序代码:
#include <iostream> #include <string> #define error 0 #define succee 1 using namespace std; class ACCOUNT { private: unsigned long ID; unsigned int password; string name; int ballance; public: ACCOUNT(unsigned long id,unsigned int pw,string 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,string n,int a) { ID=id; password=pw; name = n; ballance=a; } int ACCOUNT::cunkuan(unsigned long id,unsigned int pw,int a) { if(!check(id,pw)) return error; else { ballance+=a; return succee; cout<<"您的余额为:"<<ballance<<endl; } } int ACCOUNT::qukuan(unsigned long id,unsigned int pw,int a) { switch(a) { case 1:a=100; break; case 2:a=200; break; case 3:a=500; break; case 4:a=1000; break; } if(!check(id,pw)) return error; else { if(ballance<a) { cout<<"您的余额已不足!"<<endl; return error; } else ballance-=a; return ballance; } } int ACCOUNT::chaxun(unsigned long id,unsigned int pw) { if(!check(id,pw)) return error; else return ballance; } int ACCOUNT::check(unsigned long id,unsigned int pw) { if(id==ID&&pw==password) return succee; else return error; } int main() { ACCOUNT A(1005170228,123456,"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(); } else { cout << "★账号或是密码错误!★" << endl; } break; } cout<<"-----------------------"<<endl; cout<<"请继续选择"<<endl; cout<<"<1>存款\n<2>取款\n<3>查询余额\n<4>结束"<<endl; cin>>c; } cout<<"谢谢使用!"<<endl; getchar(); getchar(); return 0; }