16_4.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:4k
源码类别:

C#编程

开发平台:

Visual C++

  1. //16_4.cpp
  2. #include <iostream.h>
  3. #include "account.h"
  4. #include "savings.h"
  5. #include "checking.h"
  6. #include "credit.h"
  7. void DoSavings(int access);
  8. void DoChecking(int access);
  9. void DoAccess(int type);
  10. void DoCredit(int access);
  11. void main()
  12. {
  13.   int sele=1;
  14.   while(sele){
  15.     cout <<"nbank managementnn"
  16.          <<"0. Returnn"
  17.          <<"1. Savings businessn"
  18.          <<"2. Checking businessn"
  19.      <<"3. Credit businessnn"
  20.          <<"select : ";
  21.     cin >>sele;
  22.     if(sele>=1 && sele <=3)  DoAccess(sele);
  23.   }
  24.   Account* p=Account::First();   //以下善后
  25.   while(p){
  26.     Account* t=p;
  27.     p=p->Next();
  28.     delete t;
  29.   }
  30.   Account::First()=NULL;
  31. }
  32. void DoAccess(int type)
  33. {
  34.   int sele=1;
  35.   while(sele){
  36.     cout <<"nFetching or savingnn"
  37.          <<"0. Returnn"
  38.          <<"1. Fetchingn"
  39.          <<"2. Savingnn"
  40.          <<"select : ";
  41.     cin >>sele;
  42.     if(sele!=1 && sele!=2) continue;
  43.   switch(type){
  44.     case 1: DoSavings(sele); break;
  45.     case 2: DoChecking(sele); break;
  46.     case 3: DoCredit(sele); break;
  47. }
  48.   }
  49. }
  50. void DoSavings(int access)
  51. {
  52.   unsigned aN;
  53.   float val;
  54.   if(access==2){  //saving
  55.     cout <<"nplease input some account and amount for saving(input 0 for end):n";
  56.     cin >>aN >>val;
  57. while(aN && val>0){
  58.       Account* p;
  59. for(p=Account::First(); p; p=p->Next())  //finding
  60.         if(p->AccountNo()==aN && dynamic_cast<Savings*>(p)){
  61.           p->Deposit(val);
  62.           break;
  63. }
  64. if(!p)  //not found
  65.   new Savings(aN,val);
  66.       cout <<"nplease input some account and amount for saving(input 0 for end):n";
  67.       cin >>aN >>val;
  68.     }
  69.   }else{  //fetching
  70.     cout <<"please input a account number and amount for fetching(input 0 for end):n";
  71.     cin >>aN >>val;
  72.     while(aN && val>0){
  73. Account* p;
  74.     for(p=Account::First(); p; p=p->Next())  //finding
  75.         if(p->AccountNo()==aN && dynamic_cast<Savings*>(p)){
  76.           p->Withdrawal(val);
  77.           break;
  78. }
  79. if(!p)
  80. cout <<"error: the account number isn't found.n"; 
  81. cout <<"nplease input a account number and amount for fetching(input 0 for end):n";
  82.       cin >>aN >>val;
  83.     }
  84.   }
  85. }
  86. void DoChecking(int access)
  87. {
  88.   unsigned aN;
  89.   float val;
  90.   if(access==2){  //saving
  91.     cout <<"nplease input some account and amount for saving(input 0 for end):n";
  92.     cin >>aN >>val;
  93. while(aN && val>0){
  94.       Account* p;
  95. for(p=Account::First(); p; p=p->Next())  //finding
  96.         if(p->AccountNo()==aN && dynamic_cast<Checking*>(p)){
  97.           p->Deposit(val);
  98.           break;
  99. }
  100. if(!p)  //not found
  101.   new Checking(aN,val);
  102.       cout <<"nplease input some account and amount for saving(input 0 for end):n";
  103.       cin >>aN >>val;
  104.     }
  105.   }else{  //fetching
  106.     cout <<"nplease input a account number and amount for fetching(input 0 for end):n";
  107.     cin >>aN >>val;
  108.     while(aN && val>0){
  109. Account* p;
  110.     for(p=Account::First(); p; p=p->Next())  //finding
  111.         if(p->AccountNo()==aN && dynamic_cast<Checking*>(p)){
  112.           p->Withdrawal(val);
  113.           break;
  114. }
  115. if(!p)
  116. cout <<"error: the account number isn't found.n"; 
  117. cout <<"nplease input a account number and amount for fetching(input 0 for end):n";
  118.       cin >>aN >>val;
  119.     }
  120.   }
  121. }
  122. void DoCredit(int access)
  123. {
  124.   unsigned aN;
  125.   float val;
  126.   if(access==2){  //saving
  127.     cout <<"please input some account and amount for saving(input 0 for end):n";
  128.     cin >>aN >>val;
  129. while(aN && val>0){
  130.       Account* p;
  131. for(p=Account::First(); p; p=p->Next())  //finding
  132.         if(p->AccountNo()==aN && dynamic_cast<Creditcard*>(p)){
  133.           p->Deposit(val);
  134.           break;
  135. }
  136. if(!p)  //not found
  137.   new Creditcard(aN,val);
  138.       cout <<"nplease input some account and amount for saving(input 0 for end):n";
  139.       cin >>aN >>val;
  140.     }
  141.   }else{  //fetching
  142.     cout <<"nplease input a account number and amount for fetching(input 0 for end):n";
  143.     cin >>aN >>val;
  144.     while(aN && val>0){
  145. Account* p;
  146.     for(p=Account::First(); p; p=p->Next())  //finding
  147.         if(p->AccountNo()==aN && dynamic_cast<Creditcard*>(p)){
  148.           p->Withdrawal(val);
  149.           break;
  150. }
  151. if(!p)
  152. cout <<"error: the account number isn't found.n"; 
  153. cout <<"nplease input a account number and amount for fetching(input 0 for end):n";
  154.       cin >>aN >>val;
  155.     }
  156.   }
  157. }