第十二篇_异常处理.ppt

  1. 1、本文档共30页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
//account.cpp中仅以下成员函数的实现与例11-13不同,其它内容皆与之完全相同 void Account::error(const string msg) const { throw AccountException(this, msg); } //12_4.cpp仅主函数的实现与例11_13.cpp不同,其它皆与之完全相同 int main() { Date date(2008, 11, 1); //起始日期 Controller controller(date); string cmdLine; const char *FILE_NAME = commands.txt; ifstream fileIn(FILE_NAME); //以读模式打开文件 if (fileIn) { //如果正常打开,就执行文件中的每一条命令 while (getline(fileIn, cmdLine)) { try { controller.runCommand(cmdLine); } catch (exception e) { cout Bad line in FILE_NAME : cmdLine endl; cout Error: e.what() endl; return 1; } } fileIn.close(); //关闭文件 } * 12.5 综合实例——对个人银行账户管理程序的改进 例12-4(续) ofstream fileOut(FILE_NAME, ios_base::app); //以追加模式 cout (a)add account (d)deposit (w)withdraw (s)show (c)change day (n)next month (q)query (e)exit endl; while (!controller.isEnd()) { //从标准输入读入命令并执行,直到退出 cout controller.getDate() \tTotal: Account::getTotal() \tcommand ; string cmdLine; getline(cin, cmdLine); try { if (controller.runCommand(cmdLine)) fileOut cmdLine endl; //将命令写入文件 } catch (AccountException e) { cout Error(# e.getAccount()-getId() ): e.what() endl; } catch (exception e) { cout Error: e.what() endl; } } return 0; } * 12.5 综合实例——对个人银行账户管理程序的改进 例12-4(续) 例12-5(续) 运行结果如下: ......(前面的输入和输出与例9-16给出的完全相同,篇幅所限,不再重复) 2009-1-1 Total: 20482.9 command w 2 20000 buy a car Error(#C5392394): not enough credit 2009-1-1 Total: 20482.9 command w 2 1500 buy a television 2009-1-1 #C5392394 -1500 -1550 buy a television 2009-1-1 Total: 18982.9 command q 2008-12-5 2009-1-32 Error: Invalid date 2009-1-1 Total: 18982.9 command q 2008-12-5 2009-1-31 2008-12-5 #S3755217 5500 10500 salary 2009-1-1 #S3755217 17.77 10517.8 interest 2009-1-1 15.16 10015.2 interest 2009-1-1 #C5392394 -50 -50 annual fee 2009-1-1

文档评论(0)

xiaofei2001128 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档