输入代码:
/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:sum123.cpp * 作 者:林海云 * 完成日期:2014年 11 月 18日 * 版 本 号:v1.0 * * 问题描述:模仿银行取款机构造一个银行系统 * 输入描述:按要求输入 * 程序输出: */ #include <iostream> using namespace std ; const int password=123456; double money=10000; bool pass (); void work() ; void exit() ; void showbalance(); double drawmoney (double money ); double deposit(double money ); double transferAccounts (double money ); int updatePassword(int password); int main() { cout<<"烟大银行欢迎您的光临!"<<endl; cout<<"请输入密码:"; if(pass()) { cout<<endl; work(); } else cout<<"请到柜台办理密码查询后再来"<<endl; return 0; } bool pass() { int i=1,pass; bool passtrue=false; do { cin>>pass; if(pass==password) { passtrue=true; return passtrue; } else { i++; if (i < 4) cout << "密码输入错误" << i-1 << "次,再输错" << 4 - i << "次将要吞卡。" << endl; else if (i = 4) cout << "银行卡已被吞。" << endl; continue; } } while (passtrue = false || i < 4); } void work() { int choice; while(choice!=0) { cout<<"*您可以办理下面的业务:"<<endl; cout<<"*1.查询 2.取款 3.存款 4.转账 5.改密 6.退出"<<endl; cout<<"*请输入(0-5):"; cin>>choice; switch(choice) { case 0:exit();break; case 1:showbalance();break; case 2:drawmoney(money);break; case 3:deposit(money);break; case 4:transferAccounts(money);break; case 5:updatePassword(password);break; default: cout<<"输入有误,请重新输入!" <<endl; continue ; } } } void exit() { cout<<"谢谢!欢迎下次光临!"<<endl; } void showbalance() { cout << "您当前的账户余额为:" << money << "元。" << endl<< endl; work(); } double drawmoney(double money) { double outmoney; while (1) { cout << "请输入取款金额:"; cin >> outmoney; if (outmoney > money) { cout << "对不起,余额不足。" << endl; continue; } else { money -= outmoney; cout << "取款后,您的余额是:" << money << "元" <<endl<<endl; } return money; } } double deposit(double money) { double inmoney; cout << "请输入存款金额:"; cin >> inmoney; money += inmoney; cout << "存款后,您的余额是:" << money << "元。" << endl<<endl; return money; } double transferAccounts(double money) { double changemoney, otheraccount; while (1) { cout << "请输入转账金额:"; cin >> changemoney; cout << "请输入对方账户:"; cin >> otheraccount; if (otheraccount > money) { cout << "对不去,余额不足,请重新输入。" << endl; continue; cout << endl; } else { money -= changemoney; cout<<"汇款成功!"<<"您成功汇款"<<changemoney<<"元。"<<endl; cout<<"您的余额:"<<money<<"元。"<<endl<<endl; return money; } } } int updatePassword(int password) { int pass_1, pass_2; while (1) { cout << "请输入旧密码:"; if (pass()) { cout << "请输入新密码:"; cin >> pass_1; cout << "请确认新密码:"; cin >> pass_2; if (pass_1 == pass_2) { password = pass_1; cout << "密码修改成功!" << endl; return password; cout << endl; work(); } else { cout << "两次密码输入不一致,请重新输入!" <<endl; continue; } } else { cout << "请联系客服。" << endl; continue; } } }
总结:这个程序是参考别人的程序自己弄出来的,写得很长,是一个多文件的程序,主要得把握好main函数与各函数之间的联系。及办理业务的循环。
原文地址:http://blog.csdn.net/linhaiyun_ytdx/article/details/41256165