如果想不直接结束程序,输入一个提示,返回主菜单,应该怎么设计呢
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; 大家尝试下,多谢啦! }