青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

身上無錢你莫邪

moye's c++ blog

習(xí)題12.1 多態(tài)及文本讀入

Account類:
#ifndef HEADER_ACCOUNT
#define HEADER_ACCOUNT

#include 
<string>
using std::string;

class Account
{
protected:
    
string acntNumber;
    
double balance;
public:
    Account()
{}
    Account(
string acntNo,double balan=0.0);
    
virtual void display()const;
    
double getBalan()const{return balance;}
    
void deposit(double amount){balance += amount; display();}
    
bool operator==(const Account&a){return acntNumber==a.acntNumber;}
    
virtual void withdrawal(double amount){return;}
}
;

#endif
#include "StdAfx.h"
#include 
"Account.h"
#include 
<iostream>

using namespace std;

Account::Account(
string acntNo, double balan):acntNumber(acntNo),balance(balan){}

void Account::display() const{
    cout
<<"Account:"<<acntNumber<<" = "<<balance<<endl;
}

Checking類:
#ifndef HEADER_CHECKING
#define HEADER_CHECKING

#include 
<string>
#include 
"account.h"
using std::string;

//匯款方式:信匯,電匯,其他
enum REMIT{remitByPost,remitByCable,Other};

class Checking : public Account{
    REMIT remittance;
public:
    Checking()
{}
    Checking(
string acntNo,double balan=0.0);
    
void display()const;
    
void withdrawal(double amount);
    
void setRemit(REMIT re){remittance = re;}
}
;

#endif
#include "StdAfx.h"
#include 
"Checking.h"
#include 
<iostream>
using namespace std;

Checking::Checking(
string acntNo, double balan)
    :remittance(REMIT::Other)

        Account::acntNumber 
= acntNo;
        Account::balance 
= balan;
    }


void Checking::display() const{
    cout
<<"Checking ";
    Account::display();
}


void Checking::withdrawal(double amount){
    
if(remittance == REMIT::remitByPost)
        amount 
+=30;
    
if(remittance == REMIT::remitByCable)
        amount 
+=60;
    
    
if(balance<amount)
        cout
<<"Insufficient funds withdrawal: "<<amount<<endl;
    
else{
        balance 
-= amount;
        Account::display();
    }

}

Savings類:
#ifndef HEADER_SAVINGS
#define HEADER_SAVINGS

#include 
"account.h"
#include 
<string>
using std::string;

class Savings:public Account{
    
static double minBalance;
public:
    Savings()
{}
    Savings(
string acntNo,double balan=0.0);
    
void display()const;
    
void withdrawal(double amount);
}
;

#endif
#include "StdAfx.h"
#include 
"Savings.h"
#include 
<iostream>
using namespace std;

double Savings::minBalance =0;

Savings::Savings(
string acntNo,double balan){
    Account::acntNumber 
= acntNo;
    Account::balance 
=balan;
}


void Savings::display() const{
    cout
<<"Savings ";
    Account::display();
}

void Savings::withdrawal(double amount){
    
if(balance+minBalance < amount)
        cout
<<"Insufficient funds withdrawal:"<<amount<<endl;
    
else{
        balance 
-=amount;
        Account::display();
    }

}

AccountList類:
#ifndef HEADER_ACCOUNTLIST
#define HEADER_ACCOUNTLIST

#include 
"account.h"

// ---------------------//
class Node{
public:
    Account
& acnt;
    Node 
*next,*prev;
    Node(Account 
&a):acnt(a),next(0),prev(0){}
    
bool operator==(const Node& n)return acnt == n.acnt;}//最終比較acntNumber
    ~Node(){}
}
;
// ---------------------//
class AccountList
{
    
int size;
    Node 
*first;
public:
    AccountList():first(
0),size(0){};
    Node
* getFirst()constreturn first;}
    
int getSize()constreturn size;}
    
void add(Account &a);
    
void remove(string acntNo);
    Account
* find(string acntNo)const;
    
bool isEmpty()const{return !size;}
    
void display()const;
    
~AccountList();
}
;

#endif
#include "StdAfx.h"
#include 
"AccountList.h"

#include 
<iostream>
using namespace std;

void AccountList::add(Account &a){
    
//自動把新元素放在棧首
    Node* pN=new Node(a);
    
if(first){
        pN
->next = first;
        first
->prev = pN;
    }

    first 
= pN;
    size 
++;
}
//--------------------
void AccountList::remove(string acntNo){
    Account a(acntNo);
    
for(Node *= first;p;p=p->next)
        
if(*p==Node(a))//compare調(diào)用Account的==方法
            if(p->prev) p->prev->next = p->next;
            
if(p->next) p->next->prev = p->prev;
            
if(p==first) first = p->next;
            delete p;
            size
--;
            
break;
        }

}
//--------------------
Account* AccountList::find(std::string acntNo) const{
    Account a(acntNo);
    
for(Node* p=first;p;p = p->next)
        
if(*p==Node(a))
            
return &(p->acnt);
    
return 0;
}
//--------------------
void AccountList::display()const{
    cout
<<"There are "<<size<<" accounts."<<endl;
    
for(Node* p=first;p;p=p->next)
        (p
->acnt).display();
}
//--------------------
AccountList::~AccountList(){
    
for(Node* p=first;p=first;delete p){         
        first 
= first->next;         
    }
   
}


題目:
使用Account類、Savings類、Checking類及AccountList類,編寫一個應(yīng)用程序,它從文件account.txt中讀入一些帳戶號和對應(yīng)的存款額,創(chuàng)建若干個Savings和Checking帳戶,直到遇到一個結(jié)束標志“x 0”,并輸出所有帳戶號的存款數(shù)據(jù)。
account.txt內(nèi)容如下:

savings 123 70000
checking 661 20000
savings 128 2000
savings 131 5000
checking 681 200000
checking 688 10000
x 0

程序如下:
#include "stdafx.h"

#include 
"savings.h"
#include 
"checking.h"
#include 
"accountlist.h"

#include
<iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{  
    
//習(xí)題12.1
    ifstream in("account.txt");
    
string accType,accNo;
    
double balance;
    AccountList list;

    
for(string s;getline(in,s);)
    {
        istringstream sin(s);
        sin
>>accType;
        
if(accType!="x"){
            sin
>>accNo;
            sin
>>balance;
            
if(accType== "savings"){
                Savings 
*s1 = new Savings(accNo,balance);
                list.add(
*s1);
            }
            
else if (accType=="checking"){
                Checking
*c1 = new Checking(accNo,balance);
                list.add(
*c1);
            }    
        }        
    }

    
if(list.getSize()>0)
        list.display();
        system(
"pause");
    
return 0;
}

posted on 2009-02-03 12:12 莫耶 閱讀(627) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

<2025年11月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

統(tǒng)計

常用鏈接

留言簿(3)

隨筆檔案

友情鏈接

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久激情视频久久| 欧美激情精品久久久久久大尺度| 亚洲春色另类小说| 久久免费高清视频| 亚洲大片av| 亚洲激情网址| 欧美日韩精品在线视频| 一区二区三区.www| 亚洲视频中文字幕| 国产专区欧美精品| 美女主播一区| 欧美精品首页| 欧美一区二区三区在线免费观看| 午夜日韩在线| 亚洲欧洲精品一区二区三区不卡 | 欧美一区日韩一区| 激情国产一区| 亚洲另类自拍| 国产嫩草一区二区三区在线观看| 久久蜜桃资源一区二区老牛| 麻豆久久精品| 亚洲一区制服诱惑| 欧美制服丝袜| 99热在这里有精品免费| 亚洲一区成人| 亚洲国产精品一区二区www在线| 91久久亚洲| 国产欧美午夜| 亚洲人成免费| 韩国成人福利片在线播放| 亚洲高清激情| 国产一区二区欧美日韩| 亚洲黄色精品| 国产一区二区三区久久久| 欧美国产视频一区二区| 国产精品激情偷乱一区二区∴| 久久久久国产精品厨房| 欧美日韩国产一级片| 久久天天躁狠狠躁夜夜av| 欧美日韩国产一区| 美女爽到呻吟久久久久| 欧美午夜一区| 欧美激情影音先锋| 国产亚洲一区在线| 在线视频精品一| 亚洲久久一区| 久久综合国产精品| 欧美一区二区三区男人的天堂| 欧美高清成人| 免费中文日韩| 国产一区久久| 亚洲一区综合| 亚洲影视综合| 欧美日韩国产麻豆| 亚洲福利小视频| 在线观看视频亚洲| 亚洲欧美中文字幕| 亚洲欧美国产高清| 欧美日韩色婷婷| 亚洲欧洲精品一区二区三区不卡| 一区二区三区在线观看欧美| 亚洲欧美色婷婷| 午夜在线播放视频欧美| 国产精品扒开腿做爽爽爽软件| 亚洲激情第一区| 亚洲精品国产欧美| 欧美ed2k| 亚洲欧洲日产国码二区| 亚洲欧洲一区二区三区在线观看| 久久精品一区二区国产| 久久精品免费看| 国产中文一区| 久久精品国产一区二区三区免费看| 欧美亚洲一区三区| 国产欧美精品xxxx另类| 亚洲欧美日韩精品久久奇米色影视 | 一区二区三区精品视频| 亚洲欧美日韩精品久久| 欧美色图一区二区三区| 中文久久乱码一区二区| 欧美一级大片在线观看| 国产精品亚洲综合天堂夜夜| 亚洲女人天堂av| 久久久久久一区二区三区| 激情成人中文字幕| 欧美fxxxxxx另类| 亚洲精品一区二区三区99| 亚洲一区二区免费视频| 国产精品捆绑调教| 欧美在线你懂的| 男人的天堂成人在线| 99精品99| 国产女人18毛片水18精品| 欧美一区二区三区喷汁尤物| 麻豆精品在线视频| 在线综合欧美| 国产在线拍偷自揄拍精品| 麻豆精品网站| 日韩写真在线| 久久久国产成人精品| 最新日韩中文字幕| 欧美午夜剧场| 六月婷婷久久| 亚洲女人天堂av| 亚洲第一久久影院| 欧美一区二区高清| 99av国产精品欲麻豆| 国产欧美一区二区在线观看| 久久婷婷色综合| 在线亚洲精品福利网址导航| 久久在线免费观看| 亚洲欧美日韩在线| 亚洲精品乱码视频| 国产亚洲精品久久久久动| 欧美精品一区二区三| 欧美一区深夜视频| 一区二区三区免费观看| 欧美国产第二页| 久久久久九九九| 亚洲免费影视| 夜夜夜久久久| 亚洲国产精品美女| 国产一区二区在线观看免费| 欧美欧美全黄| 女女同性精品视频| 久久深夜福利免费观看| 亚洲自啪免费| 一区二区三区你懂的| 亚洲二区在线视频| 麻豆av福利av久久av| 欧美一区二区精品| 亚洲一区二区三区激情| 日韩视频一区二区在线观看| 激情av一区| 国产一区二区激情| 国产日韩高清一区二区三区在线| 欧美日韩精品免费观看视频| 久热re这里精品视频在线6| 久久精品盗摄| 欧美伊人久久久久久午夜久久久久| 在线视频精品一区| 一区二区三区久久久| aa国产精品| 亚洲一区久久| 亚洲欧美日韩成人| 亚洲一区二区三区高清| 亚洲视频一区在线| 亚洲天堂男人| 新片速递亚洲合集欧美合集| 亚洲欧美综合国产精品一区| 亚洲视频每日更新| 亚洲欧美日韩天堂| 久久国产一区二区三区| 久久精品日韩| 麻豆乱码国产一区二区三区| 久久中文精品| 欧美日韩精品一区二区天天拍小说 | 国产亚洲女人久久久久毛片| 国产精品亚洲精品| 国产一在线精品一区在线观看| 国产亚洲精久久久久久| 激情久久久久久久久久久久久久久久| 国产一区二区三区久久悠悠色av| 一区二区三区在线视频免费观看 | 在线成人激情视频| 亚洲国产欧美一区二区三区久久| 91久久在线播放| 宅男精品导航| 久久精选视频| 欧美激情中文不卡| 一本色道久久综合亚洲91| 亚洲欧美日韩精品久久亚洲区 | 欧美经典一区二区| 国产精品日韩| 原创国产精品91| 夜夜夜久久久| 久久久水蜜桃| 亚洲精品日韩综合观看成人91| 亚洲一级二级在线| 久久久久高清| 欧美视频一区二区三区四区| 国产热re99久久6国产精品| 亚洲第一级黄色片| 亚洲与欧洲av电影| 蜜月aⅴ免费一区二区三区 | 久久综合色8888| 亚洲伦理在线| 久久久免费精品| 国产精品乱码久久久久久| 在线观看91精品国产入口| 亚洲视频香蕉人妖| 免费在线观看精品| 亚洲欧美日韩中文视频| 欧美国产成人精品| 狠狠色丁香久久综合频道| 在线视频精品一区| 欧美aⅴ99久久黑人专区| 亚洲欧美成人网| 欧美美女bb生活片| 亚洲国产精品www|