? ? ? ??
#include<iostream> #include<string> using namespace std; class BaseAccount { public: ? ?static long money; ? ?const long num; public: ? BaseAccount():num(888666) ? { ? ?cout<<"请输入六位银行账户:"; ? ?long num1; ? ?while(1) ? ?{ ?cin>>num1; ?if(num==num1) ?{ ? cout<<"账号输入成功!"<<endl; ? break; ?} ?else ? cout<<"账号输入失败,请再次输入:"; ? ?} ? } ? void output() ? { ? ?cout<<"账户存款为:"; ? ?cout<<money<<endl; ? } }; long BaseAccount::money=0; class StorageAccount:public ?BaseAccount { public: ?long num2; ?string address; public: ? friend istream& operator >> (istream& cin,StorageAccount& c); ? friend ostream& operator << (ostream& cout,StorageAccount& c); ? StorageAccount():num2(111222),address("huxian") ? { ? ?cout<<"请输入六位账号密码:"; ? ?while(1) ? ?{ ?long num3; ?cin>>num3; ?if(num2==num3) ?{ ? cout<<"密码正确,请继续您的操作"<<endl; ? break; ?} ?else ? cout<<"密码错误请重新输入:"; ? ?} ? } ? void intput(long C1) ? { ? ? money+=C1; ? } ? void output1(long C2) ? { ? ?money-=C2; ? ?if( money<=0) ? ?{ ? ? cout<<"余额不足"<<endl; ? ? money+=C2; ? ?} ? } }; istream& operator >> (istream& cin,StorageAccount& c){return cin>>c.num2;} ostream& operator << (ostream& cout,StorageAccount& c){return cout<<c.address;}
void test1() { ?cout<<"请选择你的操作:"<<endl; ?cout<<"1.存款"<<endl; ?cout<<"2.取款"<<endl; ?cout<<"3.退出"<<endl; ?cout<<"4.修改密码"<<endl; ?cout<<"5.显示账户信息"<<endl; ?cout<<".............................."<<endl; }
StorageAccount S1; void test2() { ?long T; ?cout<<"请输入原密码:"; ?while(1) ?{ ? cin>>T; ? if(S1.num2==T) ? { ? ?cout<<"密码输入正确,请输入新密码:"; ? ?cin>>S1.num2; ? ?cout<<"密码修改成功!"<<endl; ? ?break; ? } ? else ? ?cout<<"密码错误,请重新输入:"; ?} ?cout<<"-----------------------------"<<endl; }
void test3() { ?cout<<"账户地址为:"<<S1.address<<endl; ?cout<<"账户余额为:"<<S1.money<<endl; ?cout<<"账户利率为:2.88%"<<endl; ?cout<<"---------------------------------"<<endl; }
void test4() { ?while(1) ?{ ?test1(); ?long B; ?cin>>B; ?if(B==1) ?{ ? long B1; ? cout<<"请输入存款金额:"; ? cin>>B1; ? S1.intput(B1); ? S1.output(); ? cout<<".............................."<<endl; ?} ?if(B==2) ?{ ? long B2; ? cout<<"请输入取款金额:"; ? cin>>B2; ? S1.output1(B2); ? S1.output(); ? cout<<".............................."<<endl; ?} ?if(B==3) ?{ ? cout<<"退出成功"<<endl; ? break; ?} ?if(B==4){test2();} ?if(B==5){test3();} ?} }
int main() { ?test4(); ?return 0; }
?
|