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

身上無錢你莫邪

moye's c++ blog

習題12.1 多態及文本讀入

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調用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類,編寫一個應用程序,它從文件account.txt中讀入一些帳戶號和對應的存款額,創建若干個Savings和Checking帳戶,直到遇到一個結束標志“x 0”,并輸出所有帳戶號的存款數據。
account.txt內容如下:

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[])
{  
    
//習題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)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

<2025年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

統計

常用鏈接

留言簿(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>
            久久精品日韩欧美| 欧美 亚欧 日韩视频在线| 亚洲精品欧洲精品| 欧美日韩精品三区| 一本久久a久久免费精品不卡| 夜夜嗨av一区二区三区| 久久精品亚洲一区二区三区浴池| 欧美剧在线观看| 亚洲伊人网站| 欧美亚洲一区二区在线观看| 一区二区在线观看视频在线观看 | 免费在线亚洲欧美| 亚洲精品一区在线观看香蕉| 999亚洲国产精| 国产最新精品精品你懂的| 欧美成人午夜剧场免费观看| 欧美日韩国产小视频| 欧美在线免费观看| 欧美福利视频网站| 先锋影音久久久| 欧美凹凸一区二区三区视频| 亚洲专区欧美专区| 久久久久**毛片大全| 亚洲视频图片小说| 久久精品成人欧美大片古装| 一区二区三区四区五区精品视频 | 性高湖久久久久久久久| 亚洲高清不卡一区| 亚洲综合激情| 亚洲美女av在线播放| 欧美在线观看网站| 一区二区动漫| 免费日韩精品中文字幕视频在线| 香蕉久久精品日日躁夜夜躁| 欧美成人亚洲| 老**午夜毛片一区二区三区| 欧美日韩精品在线视频| 免费成人毛片| 国产视频精品网| 日韩天堂在线观看| 亚洲高清视频中文字幕| 午夜激情久久久| 亚洲视频网在线直播| 你懂的网址国产 欧美| 久久久久成人网| 国产精品亚洲精品| 亚洲九九精品| 99视频一区| 毛片基地黄久久久久久天堂| 久久亚洲国产精品一区二区| 国产精品美女久久久久久免费| 亚洲国内在线| 亚洲丶国产丶欧美一区二区三区| 亚洲欧美日韩天堂| 午夜精品久久久久久久蜜桃app| 欧美激情亚洲| 亚洲国产免费看| 亚洲国产另类精品专区| 久久婷婷麻豆| 欧美激情1区| 亚洲激情中文1区| 男人的天堂亚洲| 欧美激情在线有限公司| 91久久精品视频| 欧美1区2区| 亚洲人午夜精品| 妖精视频成人观看www| 欧美日韩国产高清| 99精品欧美| 欧美一区二区在线| 国产日韩精品综合网站| 午夜精品www| 久久久久www| 亚洲丁香婷深爱综合| 久久综合色播五月| 最新日韩av| 亚洲一区国产| 国产亚洲一本大道中文在线| 久久国产精品免费一区| 欧美不卡三区| 亚洲最新在线| 国产精品进线69影院| 欧美亚洲在线观看| 免费亚洲电影在线| 亚洲精品四区| 国产精品永久免费| 久久九九久精品国产免费直播| 免费亚洲电影在线| 一区二区三区免费观看| 国产精品乱码一区二三区小蝌蚪| 欧美一区二区啪啪| 亚洲国产你懂的| 午夜一区二区三区不卡视频| 国内久久精品| 欧美日韩视频一区二区| 欧美一区二区三区免费视频| 亚洲二区在线| 午夜视频一区| 亚洲九九精品| 国产午夜精品理论片a级探花| 久久综合狠狠| 中文无字幕一区二区三区| 美女精品网站| 亚洲欧美日韩国产一区二区三区| 精品999网站| 欧美视频精品在线| 久久青青草综合| 亚洲一区二区三区四区视频| 欧美国产综合视频| 午夜视频在线观看一区| 亚洲美女性视频| 国产亚洲制服色| 欧美日韩中文字幕| 免费在线观看日韩欧美| 欧美一级在线播放| 亚洲视频电影图片偷拍一区| 亚洲电影免费在线观看| 久久久久免费观看| 亚洲欧美日韩另类精品一区二区三区| 在线成人小视频| 国产欧美在线观看一区| 欧美日本精品在线| 欧美a级大片| 久久综合影视| 久久久国产精品一区| 亚洲欧美日本国产有色| 亚洲精品小视频在线观看| 欧美成人精品福利| 久久综合久久美利坚合众国| 欧美在线视频观看| 亚洲欧美精品在线观看| av成人国产| 亚洲看片免费| 亚洲乱码日产精品bd| 91久久精品国产91久久性色tv| 一区二区视频免费完整版观看| 国产麻豆综合| 国产日产欧美一区| 国产欧美日韩高清| 国产麻豆91精品| 国产欧美一区二区三区久久| 国产精品亚洲成人| 国产美女精品视频| 国产女人18毛片水18精品| 国产欧美二区| 国产一区美女| 黑丝一区二区| 亚洲国产精品综合| 亚洲精品乱码久久久久久日本蜜臀| 在线精品福利| 亚洲美女福利视频网站| 一区二区三区视频在线| 亚洲一级免费视频| 欧美影院久久久| 久久久久久久综合日本| 免费在线观看成人av| 亚洲大胆人体视频| 99re热这里只有精品免费视频| 夜夜嗨av一区二区三区网站四季av | 最新精品在线| 99精品视频免费| 午夜免费在线观看精品视频| 欧美在线影院在线视频| 久久综合中文字幕| 亚洲国产精品va在线看黑人| 99精品视频一区| 亚洲综合国产| 老色批av在线精品| 国产精品啊啊啊| 韩国av一区二区三区在线观看| 亚洲国产午夜| 亚洲一级免费视频| 久久婷婷久久一区二区三区| 亚洲国产欧美日韩精品| 亚洲主播在线播放| 久久综合五月| 欧美天天视频| 尤物yw午夜国产精品视频| 亚洲免费电影在线| 欧美中文字幕在线| 亚洲经典视频在线观看| 午夜精品久久久久久久久久久| 另类av一区二区| 国产精品中文字幕欧美| 亚洲人成在线观看网站高清| 欧美夜福利tv在线| 亚洲三级色网| 久久国产乱子精品免费女| 欧美日韩不卡合集视频| 红桃视频一区| 欧美一区二区播放| 亚洲日本中文| 久久亚洲影院| 国产日韩欧美另类| 在线亚洲欧美视频| 亚洲国产裸拍裸体视频在线观看乱了中文 | 亚洲人成亚洲人成在线观看| 久久av免费一区| 亚洲调教视频在线观看| 欧美人成网站|