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

身上無錢你莫邪

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é)束標(biāo)志“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年12月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

統(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>
            欧美日韩国产系列| 亚洲欧美日韩另类| 久久精品日韩欧美| 日韩视频在线观看| 在线观看亚洲a| 国产精品伊人日日| 欧美日韩在线观看一区二区三区| 久久伊人亚洲| 欧美在线不卡| 亚洲欧美国产视频| 正在播放欧美一区| 亚洲精品一区二区三区99| 欧美99在线视频观看| 久久午夜电影网| 久久精品人人| 欧美在线播放高清精品| 亚洲免费伊人电影在线观看av| 日韩视频不卡| 亚洲日本乱码在线观看| 亚洲激情视频在线| 亚洲国内精品| 亚洲激情第一页| 91久久精品日日躁夜夜躁欧美| 精品成人在线视频| 黄色另类av| 激情欧美一区二区三区在线观看 | 国产精品永久免费视频| 欧美日韩综合另类| 欧美视频日韩视频| 欧美三级第一页| 欧美色精品在线视频| 欧美日韩天堂| 国产精品久久77777| 国产精品激情av在线播放| 国产精品成人国产乱一区| 国产精品扒开腿做爽爽爽软件 | 狠狠干综合网| 合欧美一区二区三区| 黄色精品在线看| 亚洲国产精品美女| 99视频在线观看一区三区| 99精品热视频| 亚洲自拍三区| 欧美在线亚洲综合一区| 久久久久国色av免费看影院| 美女福利精品视频| 亚洲国产精品综合| 亚洲激情六月丁香| 一区二区日韩| 性欧美xxxx视频在线观看| 久久精品在线播放| 欧美成人伊人久久综合网| 欧美人与性禽动交情品 | 亚洲国产精品精华液2区45| 亚洲人成欧美中文字幕| 在线亚洲自拍| 久久激情网站| 亚洲电影免费在线| 在线亚洲美日韩| 久久爱www.| 欧美欧美天天天天操| 国产精品视频九色porn| 国语自产精品视频在线看抢先版结局| 亚洲人成亚洲人成在线观看| 在线亚洲欧美| 久久综合久久综合九色| 亚洲精品国精品久久99热一| 亚洲一区精彩视频| 另类天堂视频在线观看| 欧美色视频在线| 在线免费观看一区二区三区| 中文久久精品| 久久综合九色综合久99| 日韩午夜av电影| 久久久www| 国产精品v一区二区三区| 好看的日韩视频| 亚洲性视频网址| 免费成人性网站| 亚洲五月婷婷| 欧美肥婆在线| 国产色婷婷国产综合在线理论片a| 最新中文字幕一区二区三区| 午夜久久福利| 亚洲国产欧美另类丝袜| 欧美在线视频一区二区三区| 欧美日韩国产精品专区| 一色屋精品亚洲香蕉网站| 亚洲欧美激情视频在线观看一区二区三区| 美女视频黄免费的久久| 亚洲男人第一网站| 欧美人牲a欧美精品| 亚洲成色精品| 久久精品国产久精国产一老狼| 亚洲精品一二| 欧美xart系列在线观看| 国内精品久久久久影院优| 亚洲自拍偷拍网址| 亚洲激情啪啪| 蜜臀va亚洲va欧美va天堂| 国产日韩在线一区二区三区| 亚洲一区二区三区影院| 91久久久国产精品| 久久综合九色综合欧美狠狠| 国产亚洲激情| 午夜欧美精品| 在线亚洲精品福利网址导航| 欧美精品粉嫩高潮一区二区| 亚洲成色最大综合在线| 久久久久欧美精品| 性娇小13――14欧美| 国产精品亚洲аv天堂网| 亚洲在线免费视频| 99精品国产一区二区青青牛奶| 欧美国产日产韩国视频| 亚洲激情第一页| 欧美福利视频| 另类天堂av| 亚洲黄色成人| 欧美激情视频一区二区三区在线播放| 久久美女性网| 亚洲电影毛片| 欧美激情一二区| 欧美高清在线一区| 亚洲精品一区在线观看香蕉| 亚洲国产一区在线| 欧美精品一区在线观看| 99在线热播精品免费| 亚洲人成网站精品片在线观看| 欧美激情女人20p| 夜夜爽av福利精品导航 | 国产精品一区二区女厕厕| 亚洲男女毛片无遮挡| 亚洲视频免费| 国产欧美亚洲视频| 久久久久久一区二区三区| 久久久久久久久伊人| 亚洲国产经典视频| 亚洲欧洲一区二区三区| 欧美三区不卡| 欧美在线播放一区二区| 久久激情中文| 亚洲日本一区二区三区| 日韩亚洲国产精品| 国产精品美女黄网| 久久米奇亚洲| 免费一级欧美片在线观看| 日韩一级片网址| 亚洲视频一二三| 国产在线麻豆精品观看| 欧美国产日韩免费| 欧美三区免费完整视频在线观看| 亚洲欧美日韩精品久久| 久久国产婷婷国产香蕉| 亚洲激情第一页| 夜夜狂射影院欧美极品| 国产亚洲成精品久久| 欧美福利一区| 国产精品免费区二区三区观看| 久久国产夜色精品鲁鲁99| 久久这里只有精品视频首页| 夜夜嗨av一区二区三区四区| 亚洲在线黄色| 亚洲区国产区| 亚洲女女做受ⅹxx高潮| 亚洲经典视频在线观看| 中文av字幕一区| 在线观看国产一区二区| 夜夜嗨网站十八久久| 激情亚洲网站| 一区二区精品国产| 在线观看91精品国产麻豆| 99精品视频一区| 激情欧美一区二区| 日韩视频在线观看国产| 狠狠色噜噜狠狠色综合久| 亚洲卡通欧美制服中文| 一区二区三区在线视频播放| 亚洲另类自拍| 亚洲第一搞黄网站| 亚洲午夜激情免费视频| 亚洲黄色在线视频| 午夜精品亚洲一区二区三区嫩草| 亚洲精品在线观| 久久精品首页| 午夜精品一区二区三区在线播放| 欧美成人黑人xx视频免费观看| 欧美在线观看视频| 欧美日韩专区| 亚洲第一精品夜夜躁人人躁| 国产亚洲欧美日韩美女| 一本一本久久a久久精品综合妖精| 在线播放一区| 欧美一区二区三区视频在线观看| 宅男精品视频| 欧美激情导航| 欧美电影打屁股sp| 韩国成人精品a∨在线观看| 亚洲欧美电影院| 中文国产成人精品|