/** Copyright (c) 2012, 烟台大学计算机学院 * All rights reserved. * 作 者: 张浩* 完成日期:2012 年11月25日 * 版 本 号:v1.0 * 输入描述: 略* 问题描述: 略* 程序输出:略* 问题分析: 略* 算法设计: */
#include<iostream>
using namespace std;
const int password = 123456;
bool pass();
void work();
void showbalance();
void drawmoney();
void deposit();
void transferAccounts();int main()
{ cout<<"爱浩银行欢迎您光临……"<<endl;if(pass())work();elsecout<<"不要着急,想好了再输入……"<<endl;return 0;
}//检验密码
//返回值:通过-true; 不通过-false
bool pass()
{bool bPass=false; //先假设不正确,直至正确后赋值为trueint iPass;int num=1;do{cout<<"请输入密码";if(num>1)cout<<"(提示:这是第"<<num<<"次输入密码,三次不对将吞卡)";cin>>iPass;num++;if(iPass==123456)bPass=true;}while(!bPass&&num<4); //密码不正确且次数在允许范围内return bPass; //密码正确为true,表示通过,反之……
}//处理业务
void work()
{char cChoice;bool bExit = false;do { cout<<endl<<"* 您可以办理下面的业务:"<<endl; cout<<"* 1.查询"<<endl; cout<<"* 2.取款"<<endl; cout<<"* 3.存款"<<endl;cout<<"* 4.转账"<<endl;cout<<"* 0.退出"<<endl; cout<<"* 请输入(0-4):"; cin>>cChoice;switch(cChoice){case '1':showbalance();break; case '2':drawmoney();break; case '3':deposit();break; case '4':transferAccounts();break; case '0':cout<<"欢迎您下次来存款. "<<endl;bExit=true;} }while(!bExit); return;
}//查询余额
void showbalance()
{cout<<"余额有问题,请拨打110. "<<endl;
}//取款
void drawmoney()
{ int type, days; double money, period, rate, interest; cout << "请输入取款金额:"; cin >> money; cout << "======存款期限======" << endl; cout << "1. 活期存款" << endl;cout << "2. 3个月 " << endl;cout << "3. 6个月" << endl;cout << "4. 一年 " << endl;cout << "5. 二年" << endl;cout << "6. 三年" << endl;cout << "7. 五年" << endl;cout << "请输入存款期限的代号:";cin >> type;if (type>=1 && type <=7){switch(type) //在if中嵌入了switch分情况处理{case 1: cout<<"请输入存款天数:";cin >> days;period = days/360.0;rate = 0.005;break;case 2:period = 0.25;rate = 0.031;break;case 3:period = 0.5;rate = 0.033;break;case 4:period = 1;rate = 0.035;break;case 5:period = 2;rate = 0.044;break;case 6:period = 3;rate = 0.05;break;case 7:period = 5;rate = 0.055;break; }interest = money * period * rate;cout << "到期利息为:" << interest << "元,本息合计共"<< interest + money <<"元。"<<endl; }elsecout << "选择存款类型错误!"<<endl;cout << "感谢您的使用,欢迎下次光临!"<<endl;
}//存款
void deposit()
{cout<<"勤俭持家,老一套,要保持. "<<endl;
}//转帐
void transferAccounts()
{cout<<"加快流通,繁荣经济. "<<endl;
}
运行结果:
心得体会:难难难!!!1