| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 8451 人关注过本帖
标题:如果想不直接结束程序,输入一个提示,返回主菜单,应该怎么设计呢
取消只看楼主 加入收藏
lin471306489
Rank: 4
等 级:业余侠客
帖 子:136
专家分:247
注 册:2011-8-16
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
如果想不直接结束程序,输入一个提示,返回主菜单,应该怎么设计呢
ATM.zip (418.12 KB)


希望查询完余额之后能返回以下,而不是直接结束呢:
请选择交易代码:
G(取钱)
C(查询余额)
S(存钱)
U(修改密码)
程序代码:
// 建立一个账户对象数组,并存储到文件中
#include<iostream.h>
#include<fstream.h>
#include"vector.h"
#include"strclass.h"
#include"accitem.h"
#include"common.h"
#include "Acctbook.h"
int main()
{
        // 打开文件
    ifstream InputStream("Account");
    string AccountNo;
    string AccPassword;
    string NewPassword1;
    string NewPassword2;
    double AccountCount;
    string ItemName;
    double OldAccountbook;
    //double NewAccountbook;
    Accountbook MyAccountnook;
    AccountItem FoundItem;
    string TransactionCode;
    string Count;
    double SaveCount;

    // 读入帐目本
    MyAccountnook.LoadAccountbook(InputStream);
    cout << "请输入帐号:";
    cin >> AccountNo;
    // 在帐目本中查询
    FoundItem = MyAccountnook.FindItem(AccountNo);
    if(FoundItem.IsNull() == true)
    {
        cout << "帐号不存在." << endl;
        return 0;
    }
    // 读入口令
    cout << "请输入口令:";
    cin >> AccPassword;
    // 判断口令是否正确
    if(FoundItem.GetPassword() != AccPassword)
    {
        cout << "口令错误!" << endl;
        return 0;
    }
    // 取原存款余额
    OldAccountbook = FoundItem.GetBalance();
    // 请客户选择交易代码
    cout<< "请选择交易代码:" << endl;
    cout<< "G(取钱)" << endl;
    cout<< "C(查询余额)" << endl;
    cout<< "S(存钱)" << endl;
    cout<< "U(修改密码)" << endl;
    cin >> TransactionCode;
    // 判断用户需要做什么
    if(TransactionCode == "C" || TransactionCode == "c")
    {
        // 查询存款余额
        cout << "余额是:" << FoundItem.GetBalance() << endl;
    }
    else if(TransactionCode == "G" || TransactionCode == "g")
    {
        // 取款
        cout<< "请选择取钱的数量:" << endl;
        cout<< "1(取100)" << endl;
        cout<< "2(取200)" << endl;
        cout<< "5(取500)" << endl;
        cout<< "A(取1000)" << endl;
        cout<< "B(取2000)" <<endl;
        cin >> Count;
        if(Count == "1") AccountCount = 100.;
        else if(Count == "2") AccountCount = 200.;
        else if(Count == "5") AccountCount = 500.;
        else if(Count == "A") AccountCount = 1000.;
        else if(Count == "B") AccountCount = 2000.;
        else
        {
            cout<< "选择错误" << endl;
            return 0;
        }
        // 判断存款余额是否足够
        if(OldAccountbook < AccountCount)
        {
            cout<< "存款余额不够!" << endl;
        }
        else
        {        // 修改对象的存款余额
            FoundItem.DeductBalance(AccountCount);
            // 修改帐目本
            MyAccountnook.UpdateItem(FoundItem);
            cout<< "请取钱!" << endl;
            // 将修改后的账目本写到文件中
            ofstream OutputStream("Account");
            MyAccountnook.StoreAccountbook(OutputStream);
        }
    }
    else if (TransactionCode == "S" || TransactionCode == "s")
    {
        cout<< "请输入存钱数量:";
        cin >>SaveCount;
        FoundItem.SaveAccount(SaveCount);
        MyAccountnook.UpdateItem(FoundItem);
        ofstream OutputStream("Account");
        MyAccountnook.StoreAccountbook(OutputStream);
    }
    else if (TransactionCode == "U" || TransactionCode == "u")
    {
        cout<< "请输入修改后的密码:";
        cin >>NewPassword1;
        cout<< "请再次输入修改后的密码:";
        cin >>NewPassword2;
        if (NewPassword1 == NewPassword2)
        {
            FoundItem.UpdatePassword(NewPassword1);
            MyAccountnook.UpdateItem(FoundItem);
            ofstream OutputStream("Account");
            MyAccountnook.StoreAccountbook(OutputStream);
            cout<< "密码修改成功!";
        }
        else
        {
            cout<< "密码修改失败!";
        }
    }
    return 0;

大家尝试下,多谢啦!
}
搜索更多相关主题的帖子: 菜单 修改密码 include 
2011-10-12 00:11
lin471306489
Rank: 4
等 级:业余侠客
帖 子:136
专家分:247
注 册:2011-8-16
收藏
得分:0 
其实,我想用 goto语句应该能实现的。、但是楼上:
需要有事件触发机制。在单片机上,有人用一个大的loop来做,这也是一种可行的办法。
另一种办法采用系统自带的软中断触发机制,可以节约cpu时间;这种机制在应用层的体现是select函数。
至于具体的实现,你做的相当不错了。有不清楚的地方,欢迎讨论。
这种方法我就不怎么明白,希望能尝试下,实现出来。

我也正用goto 语句尝试中
2011-10-12 10:23
lin471306489
Rank: 4
等 级:业余侠客
帖 子:136
专家分:247
注 册:2011-8-16
收藏
得分:0 
怎么还没有人实现啊!
要是没有,我就结贴啦
2011-10-12 21:17
快速回复:如果想不直接结束程序,输入一个提示,返回主菜单,应该怎么设计呢
数据加载中...
 
   



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

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