1 #include<iostream>> 2 #include<string> 3 using namespace std; 4 class Bank; 5 void menu(Bank &); 6 7 class Account{ 8 private: 9 string name; 10 string ID; 11 double yue; 12 13 public: 14 Account(string n,string id,double y){ 15 name =n; 16 ID =id; 17 yue =y; 18 } 19 string getID() { 20 return ID; 21 } 22 void showInfo() { 23 cout << "储户账号:" << ID << endl; 24 cout << "储户姓名:" << name << endl; 25 cout << "储户余额" << yue << endl; 26 } 27 28 void saving(double a){ 29 yue =yue +a; 30 } 31 32 void qukuan(double a){ 33 if(yue <a){ 34 cout<<"余额不足"<<endl; 35 } 36 else { 37 yue -= a; 38 cout << "取款成功" << endl; 39 } 40 } 41 42 }; 43 class Bank{ 44 private: 45 int accountNumber; 46 Account *account[100]; 47 48 public: 49 Bank(){ 50 accountNumber =0; 51 } 52 53 54 void createaccount(){ 55 string ID,name; 56 double yue; 57 cout<<"请输入您的账号"<<endl; 58 cin>>ID; 59 cout<<endl; 60 61 cout<<"请输入您的用户名"<<endl; 62 cin>>name; 63 64 cout<<"请输入您的存款"<<endl; 65 cin>>yue; 66 67 Account *a=new Account(ID,name,yue); 68 account[accountNumber]=a; 69 accountNumber++; 70 cout <<"当前已有储户"<<accountNumber<< endl; 71 cout<<"创建成功"<<endl; 72 // menu(*this); 73 } 74 75 void deleteaccount(){ 76 int i; string id; 77 cout<<"请输入您的账号\n"; 78 cin>>id; 79 cout <<id<< endl; 80 cout <<accountNumber<< endl; 81 for(i = 0; i<accountNumber;i++){ 82 83 if(account[i]->getID()==id) 84 delete account[i]; 85 accountNumber--; 86 cout<<"删除成功"<<endl; 87 break; 88 } 89 90 if(i=accountNumber){ 91 cout<<"不存在该用户"<<endl; 92 } 93 94 } 95 void cunkuan(){ 96 double money;double yue; 97 string id; 98 int i; 99 cout<<"请输入您要存入的账户"; 100 cin>>id; 101 102 cout<<"请输入您要存入的钱"; 103 cin>>money; 104 for(i =0; i<accountNumber;i++){ 105 if(account[i]->getID()==id) 106 //yue =money+yue; 107 account[i]->saving(money); 108 cout<<"存款成功"; 109 cout<<endl; 110 account[i]->showInfo(); 111 break; 112 } 113 if (i == accountNumber) { 114 cout << "失败" << endl; 115 } 116 } 117 118 void quqian(){ 119 int i; 120 string id; 121 double money; 122 123 cout<<"请输入您要取钱的账户"<<endl; 124 cin>>id; 125 cout<<"请输入取款金额"<<endl; 126 cin>>money; 127 128 for(i =0;i<accountNumber; i++){ 129 if(account[i]->getID() ==id) 130 account[i]->qukuan(money); 131 cout<<"取款成功"<<endl; 132 account[i]->showInfo(); 133 break; 134 135 } 136 if(i ==accountNumber){ 137 cout<<"失败"<<endl; 138 } 139 } 140 void check(){ 141 int i; 142 string id; 143 double money; 144 cout<<"请输入您要查询的户"<<endl; 145 cin>>id; 146 // cin>>money; 147 for(i=0; i<accountNumber; i++){ 148 if(account[i]->getID()==id) 149 account[i]->showInfo(); 150 break; 151 } 152 if(i ==accountNumber){ 153 cout<<"没找到"<<endl; 154 } 155 } 156 157 158 159 160 }; 161 void menu(Bank &bank){ 162 int m; 163 Bank b; 164 while(1) 165 { 166 system("cls"); 167 cout<<"----------欢迎来到民生银行-----------"<<endl; 168 cout<<"----------请选择您的业务-------------"<<endl; 169 cout<<"-----------1、开户-------------------"<<endl; 170 cout<<"-----------2、销户-------------------"<<endl; 171 cout<<"-----------3、存款-------------------"<<endl; 172 cout<<"-----------4、取钱-------------------"<<endl; 173 cout<<"-----------5、查找用户-------------------"<<endl; 174 cout<<"-----------6、退出-------------------"<<endl; 175 cin>>m; 176 177 switch(m){ 178 case 1: 179 b.createaccount(); 180 system("pause"); 181 break; 182 case 2: 183 b.deleteaccount(); 184 system("pause"); 185 break; 186 case 3: 187 b.cunkuan(); 188 system("pause"); 189 break; 190 case 4: 191 b.quqian(); 192 system("pause"); 193 break; 194 case 5: 195 b.check(); 196 system("pause"); 197 break; 198 case 6: 199 return; 200 default: 201 cout << "输入有误,请重新输入" << endl; 202 203 break; 204 205 206 } 207 } 208 } 209 210 int main() 211 { 212 Bank b; 213 menu(b); 214 215 216 return 0; 217 }
2018-07-23 18:27:34