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

身上無錢你莫邪

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>
            性欧美大战久久久久久久免费观看| 亚洲日本成人在线观看| 欧美不卡视频一区发布| 艳女tv在线观看国产一区| 久久久国产成人精品| 国产精品成人在线观看| 亚洲精品网址在线观看| 久久这里有精品视频| 亚洲欧美日韩一区在线| 欧美日韩国产综合视频在线观看中文| 极品少妇一区二区三区| 欧美一级久久久| 99国产精品久久| 欧美大片免费久久精品三p| 国语自产偷拍精品视频偷 | 艳妇臀荡乳欲伦亚洲一区| 久久影院午夜片一区| 亚洲欧美日韩在线高清直播| 欧美日韩四区| 日韩网站免费观看| 亚洲成色www8888| 久久一二三区| 一区免费观看| 久久日韩粉嫩一区二区三区| 亚洲欧美日韩另类| 国产精品成人国产乱一区| 日韩亚洲欧美成人一区| 欧美sm重口味系列视频在线观看| 久久国产99| 国产亚洲综合性久久久影院| 亚洲欧美日韩在线综合| 在线视频精品一| 欧美日韩综合在线免费观看| 亚洲日本中文字幕区| 欧美激情bt| 美女视频黄a大片欧美| 在线成人激情黄色| 免费高清在线视频一区·| 久久久91精品国产一区二区精品| 国产一区二区视频在线观看 | 亚洲黄色影片| 免费一区视频| 蜜臀av在线播放一区二区三区| 一区二区三区在线高清| 狂野欧美一区| 久久亚洲风情| 亚洲国产欧美日韩精品| 亚洲第一综合天堂另类专| 牛牛国产精品| 99国产精品视频免费观看| 亚洲精品一区二区三区蜜桃久 | 亚洲国产毛片完整版| 欧美成人午夜激情在线| 99精品久久久| 一区二区三区视频免费在线观看| 国产精品va在线| 亚洲欧美视频在线观看| 午夜视频在线观看一区二区三区| 国产欧美一区二区三区国产幕精品| 久久国产视频网| 久久精品亚洲乱码伦伦中文| 亚洲风情亚aⅴ在线发布| 欧美国产日韩一区二区在线观看| 欧美va日韩va| 亚洲一区二区成人| 亚洲免费影视| 黄色亚洲精品| 欧美国产欧美亚洲国产日韩mv天天看完整 | 亚洲一区精品视频| 亚洲影视中文字幕| 国产亚洲精品久久久| 另类激情亚洲| 欧美国产视频在线观看| 亚洲少妇一区| 亚洲欧美日韩一区二区| 极品尤物av久久免费看| 91久久综合亚洲鲁鲁五月天| 欧美性大战久久久久久久| 久久精品道一区二区三区| 蜜桃久久av一区| 亚洲天堂av高清| 欧美一区二区视频在线观看| 亚洲福利视频三区| 日韩亚洲欧美高清| 国产一区二区三区四区hd| 免费观看成人鲁鲁鲁鲁鲁视频| 欧美精品18+| 欧美一区二区三区免费大片| 久久露脸国产精品| 在线视频免费在线观看一区二区| 亚洲男女自偷自拍| 亚洲国产精品久久久久秋霞不卡 | 久久久久久国产精品mv| 麻豆av福利av久久av| 亚洲尤物影院| 久久精品视频在线播放| 99这里只有精品| 欧美一级播放| 亚洲美女中出| 欧美在线一区二区| av不卡在线| 久久精品五月| 亚洲小少妇裸体bbw| 久久精品主播| 亚洲一区二区三区成人在线视频精品| 欧美一区二区三区在线| 日韩午夜在线电影| 欧美一区国产一区| 一区二区三区黄色| 久久久国产成人精品| 亚洲一区二区三区777| 久久综合导航| 欧美一区亚洲| 欧美日韩不卡| 免费观看成人网| 国产欧美精品| av成人动漫| 91久久久亚洲精品| 欧美一级免费视频| 亚洲一区日韩在线| 午夜精品一区二区三区在线视| 久久不射网站| 亚洲视频在线二区| 久久免费偷拍视频| 欧美一区二区三区久久精品| 欧美福利一区| 久久免费黄色| 国产精品美女久久久久av超清| 亚洲国产精品久久久久秋霞不卡 | 亚洲一区二区精品在线| 最新成人av网站| 久久国产精品一区二区三区四区| 亚洲婷婷综合久久一本伊一区| 久久综合久久88| 久久久精品动漫| 国产精品免费网站| 亚洲欧洲精品一区| 亚洲国产精品黑人久久久| 欧美中文在线字幕| 亚洲欧美日本在线| 欧美理论视频| 亚洲第一黄网| 亚洲成人资源网| 欧美在线视频播放| 欧美一区二区成人| 国产精品成人在线观看| 日韩亚洲欧美在线观看| 99香蕉国产精品偷在线观看| 欧美xart系列在线观看| 免费不卡在线视频| 国内精品久久久久久| 亚洲欧美日本视频在线观看| 亚洲淫性视频| 欧美午夜不卡在线观看免费 | 香蕉成人伊视频在线观看| 欧美视频手机在线| 日韩视频免费在线| 99re6热只有精品免费观看| 欧美ab在线视频| 亚洲第一视频| 亚洲激情图片小说视频| 久久中文字幕一区二区三区| 欧美成人福利视频| 1000部国产精品成人观看| 久久婷婷人人澡人人喊人人爽| 久久中文在线| 激情文学综合丁香| 欧美在线播放一区二区| 欧美与黑人午夜性猛交久久久| 国产精品xxx在线观看www| av不卡在线看| 午夜精品国产| 国产欧美日韩激情| 午夜影院日韩| 麻豆成人在线播放| 亚洲国产成人tv| 欧美国产一区视频在线观看| 亚洲激情视频| 这里只有精品视频| 欧美午夜精品久久久久久孕妇| 亚洲视频免费看| 欧美一区二区在线观看| 国产香蕉久久精品综合网| 久久精品一区| 欧美激情综合| 一区二区国产日产| 欧美亚洲第一区| 午夜精品福利一区二区三区av | 亚洲人成网站色ww在线| 欧美激情小视频| 一本综合久久| 欧美中文字幕不卡| 激情亚洲网站| 欧美大片一区二区| 一区二区三区国产在线观看| 性色av一区二区三区红粉影视| 国产亚洲精品美女| 久久综合五月天婷婷伊人| 亚洲国产婷婷| 亚洲欧美日韩在线综合|