12週間...銀行システム強化版

4951 ワード

問題およびコード:
/*
*Copyright (c) 2014,         
*All rights reserved.
*    :bank.cpp
*  :  
*    :2014 11 16 
*   :v1.0
*
*    :    
*    :      ,      
*    :      ,      
*/
#include <iostream>
using namespace std;
int password=123456;//    ,       ,       
double balance=100000000;//           

bool pass();
void work();
void showbalance();
void drawmoney();
void deposit();
void transferAccounts();
void updatepassword();
int main()
{
    cout<<"         "<<endl;
    if (pass())//          ,    work
        work ();
    else
        cout<<" ,    ,       :"<<endl;
    return 0;
}
bool pass ()
{
    bool ipassword=false;//      ,        true
    int repassword;
    int n=1;
    do
    {
        cout<<"     :";
        if (n>1)
            cout<<"   "<<n<<"     ,          "<<endl;
        cin>>repassword;
        n++;
        if (repassword==password)
            ipassword=true;

    }
    while (!ipassword&&n<=3);
    return ipassword;
}
void work ()//        
{
    char Cchoice;//        ,       
    bool exit=false;
    for (; !exit;)
    {
        cout<<"*****         *****"<<endl;
        cout<<"*1.    2.    3.    4.    5.      0.  "<<endl;
        cout<<"       0~5:";
        cin>>Cchoice;
        switch(Cchoice)
        {
        case '1':
            showbalance();
            break;
        case '2':
            drawmoney();
            break;
        case '3':
            deposit();
            break;
        case '4':
            transferAccounts();
            break;
        case '5':
            updatepassword();
            break;
        case '0':
            cout<<"                "<<endl;
            exit=true;
        }
    }
    return ;
}
void showbalance()//      
{
    cout<<" ,       :"<<balance<<" 。。  。。   "<<endl;
}
void drawmoney()//      
{
    double outmoney,leftmoney;
    cout<<"       :";
    cin>>outmoney;//      
    if (outmoney>balance)
        cout<<"        "<<endl;
    else
        leftmoney=balance-outmoney;//      
    cout<<"     :"<<leftmoney<<" 。。    。。     "<<endl;
}
void deposit()//    
{
    double addmoney,summoney;
    cout<<"       :";
    cin>>addmoney;//      
    summoney=balance+addmoney;//        
    cout<<"     :"<<summoney<<" ,  ,    "<<endl;
}
void transferAccounts()//    
{
    long user,reuser;//       ,       
    double money,leftmoney;//            
    cout<<"       :";
    cin>>money;//      
    cout<<"       :";
    cin>>user;//      
    cout<<"         :";
    cin>>reuser;//        
    if (user==reuser)
    {
        if (money>balance)//        
            cout<<"      ,      !"<<endl;
        else
        {
            leftmoney=balance-money;
            cout<<"   "<<user<<"  "<<money<<" ,     :"<<leftmoney<<" "<<endl;
        }
    }
    else
    {
        cout<<"        ,        "<<endl;
    }
}
void updatepassword()//      
{
    int newpassword,renewpassword,ipassword;
    cout<<"      :";
    cin>>ipassword;//     
    if(ipassword!=password)//           
        cout<<"    !    "<<endl;
    else
    {
        cout<<"      :";
        cin>>newpassword;
        cout<<"      :";
        cin>>renewpassword;
        if (newpassword!=renewpassword)
            cout<<"       ,       "<<endl;
        else
        {
            password=newpassword;
            cout<<"      !"<<endl;
        }
    }
}

実行結果:
心得:
この问题は难しくありませんが、面倒なので、注意しなければならないところが多すぎます...だから気をつけて