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

身上無錢你莫邪

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   管理


公告

導航

<2009年2月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567

統計

常用鏈接

留言簿(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ⅴ免费一区二区三区| 一区二区三区色| 国产乱子伦一区二区三区国色天香| 亚洲男人的天堂在线aⅴ视频| 亚洲国产欧美另类丝袜| 欧美精品一区二区三区一线天视频| 国外成人在线| 欧美在线观看日本一区| 99在线精品视频| 欧美a级大片| 韩国成人福利片在线播放| 媚黑女一区二区| 欧美日韩国产成人在线| 91久久精品美女高潮| 久久久亚洲欧洲日产国码αv | 午夜精品久久久久久久99水蜜桃 | 欧美激情精品久久久久久蜜臀| 欧美国产欧美亚洲国产日韩mv天天看完整 | 亚洲精品久久久一区二区三区| 久久成人免费| 亚洲欧美一区二区原创| 国产精品国产馆在线真实露脸| 亚洲精选中文字幕| 欧美国产日韩一区二区在线观看 | 久久久久网站| 在线观看欧美日韩| 毛片精品免费在线观看| 久久精品国产成人| 国产免费一区二区三区香蕉精| 久久久久久久97| 久久久久久久97| 亚洲视频一区在线| 亚洲一本大道在线| 国产精品制服诱惑| 亚洲国产精品小视频| 国产精品羞羞答答xxdd| 久久久精品性| 欧美精品久久久久久久久久| 亚洲一区二区免费| 午夜在线a亚洲v天堂网2018| 国产在线观看一区| 欧美激情aⅴ一区二区三区| 欧美午夜一区二区| 久久丁香综合五月国产三级网站| 欧美成人免费大片| 一区二区三区高清不卡| 久久亚洲精品伦理| 在线亚洲伦理| 欧美国产91| 亚洲国产精品va在线看黑人| 国语自产精品视频在线看一大j8 | 久久天天躁狠狠躁夜夜爽蜜月| 亚洲欧美日韩一区| 国产精品二区二区三区| 亚洲欧洲另类| 国产拍揄自揄精品视频麻豆| 欧美不卡三区| 国产精品久久久久久妇女6080| 亚洲高清不卡在线| 国产欧美不卡| 亚洲女性裸体视频| 亚洲国产成人不卡| 一区二区三区欧美日韩| 在线中文字幕一区| 国产精品日韩欧美| 亚洲专区免费| 久久狠狠亚洲综合| 欧美日韩精品一区二区三区| 亚洲国产婷婷| 一区二区三区.www| 国产精品美女999| 欧美刺激性大交免费视频| 欧美体内she精视频在线观看| 亚洲精品永久免费| 亚洲电影免费观看高清| 一区二区三区四区蜜桃| 亚洲永久视频| 欧美日韩高清免费| 一区二区三区不卡视频在线观看| 亚洲男人av电影| 国产私拍一区| 亚洲一区二区三区在线播放| 亚洲狼人综合| 欧美视频不卡| 欧美在线观看视频在线 | 一区二区三区在线免费播放| 一区二区三区www| 久久精品国产一区二区电影 | 有码中文亚洲精品| 欧美成人一区二区| 亚洲无人区一区| 久久亚洲精品伦理| 国产日韩视频| 久久躁日日躁aaaaxxxx| 久久久天天操| 99伊人成综合| 欧美精品一区二区蜜臀亚洲| 亚洲午夜羞羞片| 老司机免费视频一区二区三区| 亚洲精品乱码| 国产亚洲欧洲一区高清在线观看 | 久久香蕉精品| 中日韩美女免费视频网站在线观看| 亚洲精品午夜| 国产九九视频一区二区三区| 麻豆成人在线播放| 亚洲国产精品成人综合色在线婷婷| 亚洲欧美福利一区二区| 尤物九九久久国产精品的特点 | 午夜视频一区在线观看| 亚洲大胆女人| 在线看片一区| 国产精品青草综合久久久久99 | 蜜桃av一区二区在线观看| 亚洲一区二区三区中文字幕在线| 亚洲第一区中文99精品| 久久精精品视频| 亚洲午夜一区| 一本久道久久综合狠狠爱| 黄色亚洲免费| 国产乱理伦片在线观看夜一区| 欧美日韩国产一级片| 免费中文字幕日韩欧美| 久久精品亚洲国产奇米99| 欧美jizzhd精品欧美喷水| 先锋影音国产一区| 黑人巨大精品欧美一区二区| 国产精品久久久| 欧美日韩免费高清一区色橹橹| 亚洲视频免费在线观看| 亚洲精品在线观| 亚洲日本成人女熟在线观看| 亚洲欧美精品中文字幕在线| 亚洲狼人综合| 一本色道久久综合亚洲精品不卡 | 欧美一二区视频| 亚洲欧美成人一区二区三区| 中文无字幕一区二区三区| 亚洲美女少妇无套啪啪呻吟| 亚洲精品网站在线播放gif| 亚洲人成绝费网站色www| 亚洲国产精品va在线观看黑人| 激情欧美一区二区三区| 黄色在线一区| 在线观看日韩av| 亚洲黄色在线| 日韩一区二区久久| 国产亚洲一区二区三区在线观看| 国产精品视屏| 国产午夜精品美女视频明星a级| 国产欧美精品久久| 一区二区三区在线高清| 激情婷婷亚洲| 亚洲激情成人在线| 一本久久综合| 亚洲女同在线| 久久久久一本一区二区青青蜜月| 久久青草久久| 亚洲电影第三页| 日韩亚洲欧美一区| 欧美高清免费| 亚洲精品欧美| 日韩视频在线你懂得| 在线性视频日韩欧美| 性欧美1819sex性高清| 久久九九精品99国产精品| 久久九九免费| 欧美日韩精品免费观看视频| 欧美色欧美亚洲另类二区| 国产视频观看一区| 亚洲精品国产系列| 亚洲综合社区| 老司机精品视频网站| 亚洲精品国产精品国自产观看| 中日韩视频在线观看| 久久亚洲精品欧美| 国产精品久久久久久久久免费| 一区免费观看| 亚洲欧美另类在线| 老牛国产精品一区的观看方式| 亚洲精品孕妇| 久久久人成影片一区二区三区观看 | 亚洲茄子视频| 欧美一区二区三区四区夜夜大片| 亚洲一区国产| 欧美精品粉嫩高潮一区二区| 国产亚洲在线| 亚洲影视九九影院在线观看| 老司机67194精品线观看| 亚洲在线观看视频网站|