标题:C++ 有关 ATM 系统,怎么使用文件保存上一次的值。
只看楼主
汐悠月
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2014-5-27
 问题点数:0 回复次数:0 
C++ 有关 ATM 系统,怎么使用文件保存上一次的值。
#include<iostream>
using namespace std;
#include<windows.h>
static int zong=5000;
class ATM
{
public:
    void time();
    void denglu();
    void zhuyemian();
    void djmian();
    int cunkuan();
    int qukuan();
    int chaxun();
    void get();
    void zhuanzhang();
    void tuichu();
};
void ATM::time()
{
    cout<<"系统正在处理,请稍候......"<<endl;
}
void ATM::zhuyemian()
{
    int A;

    cout<<"--------------------------------------------------------------------------"<<endl;
    cout<<"\t---                        1:用户登录                    ---\t"<<endl;
    cout<<"\t---                        2:注销登录                    ---\t"<<endl;
    cout<<"---------------------------------------------------------------------------"<<endl;
    cout<<"请输入你需要的操作(1/2)"<<endl;
    cin>>A;
    if(A>0&&A<3)
    {
        switch(A)
        {
        case 1:denglu();break;
        case 2:tuichu();break;
        }
    }
    else
    {
        cout<<"请输入正确的数字"<<endl;
        cin.get();
        zhuyemian();

    }
}
void ATM::denglu()
{
   
    int id,pw;
    cout<<"请输入卡号:";
    cin>>id;
    if(id>000001&&id<999999)
    {
        cout<<"请输入密码: ";
        cin>>pw;

     if(id==pw)
        {
            cout<<"登录成功,请选择需要办理的业务:"<<endl;
            djmian();
        }
        else
        {
            cout<<"请输入正确的帐号密码"<<endl;
            zhuyemian();
        }
        

    }

}
void ATM::djmian()
{
    int B;
    cout<<"--------------------------------------------------------------"<<endl;
    cout<<"------\t          1.取款业务                  ----------    \t"<<endl;
    cout<<"------\t          2.存款业务                  -----------   \t"<<endl;   
    cout<<"------\t          3.查询业务                  -----------   \t"<<endl;
    cout<<"------\t          4.转账业务                  -----------   \t"<<endl;   
    cout<<"------\t          5.退出系统                  ------------  \t"<<endl;   
    cout<<"--------------------------------------------------------------"<<endl;
    cout<<"请输入操作数进行操作: "<<endl;
    cin>>B;
    if(B>0&&B<6)
    {
        switch(B)
        {
        case 1:qukuan();break;
        case 2:cunkuan();break;
        case 3:chaxun();break;
        case 4:zhuanzhang();break;
        case 5:tuichu();break;
        }
    }
    else
    {
        cout<<"请输入正确的操作数: "<<endl;
        djmian();
    }
}
int ATM::qukuan()
{

    int qu;
    cout<<"请输入取款的金额: "<<endl;
    cin>>qu;
    if(qu>zong)
    {
        cout<<"对不起,你的余额不足..."<<endl;
        qukuan();
    }
    else
    {
        if(qu%100!=0)
        {
            cout<<"请输入金额是100的倍数的金额..."<<endl;
            qukuan();
        }
        else
        {
            zong=zong-qu;
            cout<<"取款成功,请收好钱"<<endl;
            cout<<"你现在的金额为"<<zong<<endl;
            cout<<"请选择其他业务"<<endl;
            djmian();

        }
    }
    return 0;
}
int ATM::cunkuan()
{

    int cun;
    cout<<"清输入存款的金额: "<<endl;
    cin>>cun;
        if(cun%100!=0)
        {
            cout<<"请输入金额是100的倍数的金额..."<<endl;
            cunkuan();
        }
        else
        {
            zong=zong+cun;
            cout<<"存款成功,钱已到账."<<endl;
            cout<<"你现在的金额为: "<<zong<<endl;
            cout<<"请选择其他业务"<<endl;
            djmian();
        
        }
   
return 0;
}
int ATM::chaxun()
{
    cout<<"你的余额为:"<<zong<<endl;
    cout<<"请输入操作数进行操作"<<endl;
 djmian();
 return 0;
}
void ATM::zhuanzhang()
{
    int zh;
    int card;
    cout<<"请输入转账的卡号:"<<endl;
    cin>>card;
    if(card>000001&&card<999999)
    {
        cout<<"请输入转账的金额:"<<endl;
        cin>>zh;
        if(zh%100!=0)
        {
            cout<<"请输入金额是100的倍数的金额..."<<endl;
            zhuanzhang();
        }
        else
        {
            cout<<"转账成功,请选择其他操作..."<<endl;
        }    djmian();
    }
    else
    {
        cout<<"请输入正确的卡号..."<<endl;
        zhuanzhang();
    }
    return;
}        
void ATM::tuichu()
{

    cout<<endl;
    cout<<"欢迎下次光临"<<endl;
    return ;
}
int main()
{

    ATM one;
    one.zhuyemian();
    return 0;
}
搜索更多相关主题的帖子: include public 
2014-05-27 21:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-432163-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.062909 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved