Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2350458
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:00:24

#include
       using namespace std;
       #include
       #include
     
       class Account{
           int id;//帐号id设置为8位
           string usrname;
          int pwd;//密码为6位
         double money;//余额
         bool onLine;//是否在线
      public:
          static int clientsNum;//银行总的客户数目
          Account(){}
          Account(int id,string name,int pwd,double money):id(id),usrname(name),pwd(pwd),money(money){
              onLine = false;
          }
          int getId(){//获得id
              return id;
          }
          void setId(int id){
              this->id = id;
          }
          string getUsrname(){
              return usrname;
         }
          void setUsrname(string usrname){
              this->usrname = usrname;
          }
          int getPwd(){
              return pwd;
          }
         void setPwd(int pwd){
             this->pwd = pwd;
          }
          double getMoney(){
              return money;
          }
         void setMoney(double money){
              this->money = money;
          }
         char choose(){
              char ch;
              cout<<"请选择您的业务:"<              cout<<"=====1.存款====="<              cout<<"=====2.取款====="<              cout<<"===3.查询余额==="<              cout<<"===4.修改密码==="<              cout<<"=====5.转帐====="<              cout<<"=====6.退出====="<              cin>>ch;
              return ch;
          }
          void work(char op){//根据选择进行业务
             switch(op){
                  case('1'):
                      save();
                    break;
                  case('2'):
                     get();
                     break;
                 case('3'):
                      query();
                      break;
                  case('4'):
                     reset();
                     break;
                  case('5'):
                      trans();
                     break;
                case('6'):
                      exit();
                      break;
                  default:
                      break;
             }
          }

--------------------next---------------------
 void reset(){
              if(checkPwd()){
                  int pw1,pw2;
                  cout<<"请输入新密码:";
                 cin>>pw1;
                  cout<<"请再次输入新密码:"<                  cin>>pw2;
                 if(pw1==pw2){
                      pwd = pw1;
   
                      cout<<"操作成功!"<                 }else
                     cout<<"两次输入不一致!"<              }else{
                 cout<<"密码错误!"<             }
         }
          void trans(){//转帐函数
             if(checkPwd()){
                 int aimId;
                 cout<<"输入您要转到的帐户ID:";
                 do{
                    cin>>aimId;
              }while(aimId==this->id);//不允许输入本ID
                 const int len = Account::clientsNum;
                 ifstream fin("database.txt");
                if(fin){
                     int id[len];
                    string name[len];
                    int pwd[len];
                    double money[len];
                     int place = len;
                    for(int i=0;i                         fin>>id[i]>>name[i]>>pwd[i]>>money[i];
                    }
                     for(int r=0;r                         if(aimId == id[r]){//找到了目标ID
                             double cash;
                             cout<<"请输入您要转帐的金额:";
                             do{
                                 cin>>cash;
                            }while(cash<=0);
                             if(cash<=this->money){
                                money[r]+=cash;//目标ID的帐户增加cash
                                place = r;
                                 int c = find(id,this->id,len);
                                 money[c]-=cash;//本帐户减少cash
                                this->money-=cash;//
   
                                write(id,name,pwd,money);//更新信息
                              cout<<"转帐成功!"<                                 break;
                            }else{
                                 place = r;
                               cout<<"余额不足!"<                             }
                         }
                     }
                    if(place==len)
                         cout<<"你的目标ID不存在!"<                 }else{
                     cout<<"数据库文件丢失!"<                }
                 fin.close();
             }
         }
         int find(int id[],int myid,int len){
             for(int i=0;i                 if(id[i] == myid){
                    return i;break;
                 }
            }
             return -1;
       }
        void write(int id[],string name[],int pwd[],double money[]){//更新信息
             ofstream fout("database.txt");
            if(fout){
               int len = Account::clientsNum;
                for(int i=0;i                    fout<                }
             }else{
                 cout<<"数据库文件丢失"<            }
             fout.close();
       }
        bool checkPwd(){//密码验证
             int pw;
             cout<<"请输入密码:";
             cin>>pw;
             if(pwd==pw)
                 return true;
            return false;
        }
         void save(){//存钱
             double cash;
             cout<<"请输入金额:"<             do{
                 cin>>cash;
            }while(cash<=0);
             if(cash>0&&checkPwd()){
                 money+=cash;
                 cout<<"存款成功!";
             }else{
                 cout<<"存款失败!"<            }
        }
        void get(){//取钱
             double cash;
             cout<<"请输入金额:";
             do{
                 cin>>cash;
             }while(cash<=0);
             if(cash>0&&money>cash&&checkPwd()){
                money-=cash;
                 cout<<"取款成功!"<             }else{
       

--------------------next---------------------
   
     int Account::clientsNum = 10;//设置帐户书目初始化为10
class Client{
         int id;
         bool onLine;
     public:
        Client(int id):id(id){ onLine = false;}//构造函数
         void run(){           //运行
             onLine = true;
             int len = Account::clientsNum;
             Account accounts[len];
         cout<           do{
                 getAccounts(accounts,len);//获得数据库中的帐户
                 cout<<"     NB银行为您服务!"<                 cout<<"====1.进入客户类服务===="<                 cout<<"====2.退出客户类服务===="<                 char ch;
               cin>>ch;
                 if(ch == '1'){
                     int current = checkId(accounts,len,insertCard());
                     if(current!= -1){//存在帐户,在数据库中的位置为current
                        accounts[current].run();
                    }else
                       cout<<"不存在这样一个帐户!"<               }else{
                   exit();
                 }
             }while(onLine);
         }
         void getAccounts(Account accounts[],int len){//初始化len个帐户,从文件"database.txt"中读入
             ifstream fin("database.txt");
             if(fin){//如果读取成功,初始化
                 for(int i=0;i                     int id;
                     string usrname;
                     int pwd;
                     double money;
                    fin>>id>>usrname>>pwd>>money;
                    accounts[i].setId(id);
                    accounts[i].setUsrname(usrname);
                    accounts[i].setPwd(pwd);
                     accounts[i].setMoney(money);
                 }
             }else
                 cout<<"数据库文件丢失!请尽快恢复!"<             fin.close();
         }
         int insertCard(){//获得ID,不过不是真的从银行卡,而是输入
             int id;
             cout<<"请插入银行卡(在这里输入数据库中存在的一个帐户ID):";
             cin>>id;
             return id;
        }
         int checkId(Account accounts[],int len,int id){//寻找输入的帐号,并返回它的位置
             for(int i=0;i                 if(accounts[i].getId()==id)
                     return i;
             }
             return -1;
        }
         void exit(){
             onLine = false;
         }
    };
   class BankManager{
         int id;
         bool onLine;
     public:
         BankManager(int id):id(id){onLine = false;}
         void run(){
             onLine = true;
             cout<            if(checkPwd()){
                 do{
                     work(choose());
               }while(onLine);//必需要有 ";"
                cout<<"谢谢使用,再见!"<             }
   
         }
         char choose(){
            char ch;
             cout<<"请选择您的操作:"<            cout<<"=======1.创建银行客户==========="<            cout<<"=======2.退出管理员身份========="<             cin>>ch;
             return ch;
         }
         void work(char ch){
             switch(ch){
                 case '1':
                     creat();
                     break;
                case '2':
                    exit();
                     break;
                 default:
                     break;
             }
         }
         void creat(){
             int id;
             int pwd;
             string name;
             double money;
            cout<<"输入ID,密码,姓名,和要存入的钱数:"<            cin>>id>>pwd>>name>>money;
             ofstream fout("database.txt",ios::app);
            if(fout){//成功读取文件
               fout<                 cout<<"成功添加客户:"<               Account::clientsNum ++;//成功添加客户,客户数加一
            }else
                 cout<<"数据库文件找不到!"<             fout.close();
         }
         bool checkPwd(){
             int pwd;
             cout<<"请输入管理员密码:"<             cin>>pwd;
             if(pwd==5555){
                 cout<<"欢

--------------------next---------------------
C:\Documents and Settings\01\桌面\Cpp1.cpp(105) : error C2057: expected constant expression
C:\Documents and Settings\01\桌面\Cpp1.cpp(105) : error C2466: cannot allocate an array of constant size 0
C:\Documents and Settings\01\桌面\Cpp1.cpp(105) : error C2133: 'id' : unknown size
C:\Documents and Settings\01\桌面\Cpp1.cpp(106) : error C2057: expected constant expression
C:\Documents and Settings\01\桌面\Cpp1.cpp(106) : error C2466: cannot allocate an array of constant size 0
C:\Documents and Settings\01\桌面\Cpp1.cpp(106) : error C2133: 'name' : unknown size
C:\Documents and Settings\01\桌面\Cpp1.cpp(107) : error C2057: expected constant expression
C:\Documents and Settings\01\桌面\Cpp1.cpp(107) : error C2466: cannot allocate an array of constant size 0
C:\Documents and Settings\01\桌面\Cpp1.cpp(107) : error C2133: 'pwd' : unknown size
C:\Documents and Settings\01\桌面\Cpp1.cpp(108) : error C2057: expected constant expression
C:\Documents and Settings\01\桌面\Cpp1.cpp(108) : error C2466: cannot allocate an array of constant size 0
C:\Documents and Settings\01\桌面\Cpp1.cpp(108) : error C2133: 'money' : unknown size

--------------------next---------------------

阅读(1304) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~