⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f1511.cpp

📁 it is a usefull thing
💻 CPP
字号:
//=====================================
// f1511.cpp
// 引用的动态转型
//=====================================
#include<iostream>
#include<typeinfo>
using namespace std;
#include"savings_bro.h"
#include"checking_bro.h"
#include"accountlist.h"
//-------------------------------------
int main(){
  Savings s1("3277",3000), s2("3279", 5000);
  Checking c1("888"), c2("398", 10000);
  AccountList a;
  a.add(s1);  a.add(s2);
  a.add(c1);  a.add(c2);
  Account* p;
  if(p = a.find("3277")) p->deposit(100);
  if(p = a.find("888"))  p->deposit(2000);
  if(p = a.find("3279")) p->withdrawal(2500);
  if(p = a.find("398"))  p->withdrawal(1555.5);
  for(Node* p=a.getFirst(); p; p=p->next)
    try{
        dynamic_cast<Checking&>(p->acnt).deposit((p->acnt).getBalan()*0.05);
    }catch(bad_cast&){
      double temp = (p->acnt).getBalan()*0.1;
      (p->acnt).deposit(temp);
    }
  a.display();
}//====================================

 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -