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

身上無錢你莫邪

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>
            久久亚洲高清| 久久久精品一区| 欧美性猛交视频| 亚洲综合视频1区| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 欧美精品一区二区三区久久久竹菊| 精品91在线| 欧美国产日本在线| 欧美激情在线免费观看| 亚洲手机在线| 欧美在线观看天堂一区二区三区| 精品成人一区二区三区| 亚洲国产成人tv| 欧美精品在线免费| 性久久久久久| 久久久成人网| 亚洲视频高清| 久久成人精品电影| 亚洲日本欧美天堂| 亚洲欧美日本日韩| 亚洲三级毛片| 亚洲欧美制服另类日韩| 亚洲经典在线| 亚洲综合色激情五月| 在线精品视频一区二区三四| 亚洲欧洲日韩在线| 国产在线精品一区二区夜色| 亚洲欧洲精品一区| 国产午夜精品久久久久久免费视| 欧美激情一区二区三区不卡| 国产精品毛片一区二区三区| 欧美不卡在线视频| 国产欧美日本一区二区三区| 美女爽到呻吟久久久久| 亚洲精品影视在线观看| 亚洲男女自偷自拍| 玖玖综合伊人| 久久黄色级2电影| 欧美日韩一区二区精品| 麻豆精品网站| 国产欧美丝祙| 一区二区不卡在线视频 午夜欧美不卡'| 国产欧美一区二区三区视频| 亚洲伦伦在线| 亚洲日本精品国产第一区| 欧美在线播放高清精品| 亚洲综合三区| 欧美日韩视频在线一区二区| 亚洲成色www久久网站| 好看的av在线不卡观看| 午夜久久影院| 欧美亚洲免费高清在线观看| 欧美日韩精品| 亚洲激情第一区| 亚洲激情六月丁香| 久久久久五月天| 久久久久久伊人| 国产日韩一区在线| 亚洲欧美在线另类| 性视频1819p久久| 国产精品久久久久久久9999| 亚洲精品综合久久中文字幕| 亚洲乱码国产乱码精品精天堂| 久久综合久久美利坚合众国| 欧美a级片一区| 亚洲国产日韩美| 你懂的国产精品永久在线| 久久综合狠狠综合久久综合88| 国产一区二区三区在线观看精品 | 尤物九九久久国产精品的特点 | 一片黄亚洲嫩模| 亚洲午夜在线观看视频在线| 欧美日韩在线高清| 99精品国产高清一区二区| 一区二区三区 在线观看视频| 欧美激情一区二区三区全黄 | 欧美成人午夜激情视频| 在线日韩精品视频| 久久综合中文色婷婷| 亚洲国产成人久久综合一区| 亚洲美女色禁图| 欧美视频日韩视频在线观看| 亚洲一区二区三区在线看| 欧美一区二区三区日韩| 国产一区二区三区无遮挡| 久久久久免费观看| 亚洲国产乱码最新视频 | 国产乱子伦一区二区三区国色天香| 亚洲天堂久久| 久久综合色播五月| 亚洲精品护士| 国产精品久久久久免费a∨ | 亚洲激情视频| 午夜日韩电影| 亚洲第一综合天堂另类专| 欧美日本一区| 欧美一区在线看| 亚洲国产欧美在线人成| 性xx色xx综合久久久xx| 悠悠资源网久久精品| 欧美日韩免费精品| 欧美中文字幕在线| 亚洲人成人一区二区在线观看| 亚洲欧美日韩精品久久| 在线观看一区视频| 国产精品不卡在线| 久久综合网色—综合色88| 一区二区三区|亚洲午夜| 久久亚洲综合| 亚洲影院高清在线| 亚洲二区三区四区| 国产精品男女猛烈高潮激情 | 欧美日韩一区三区四区| 欧美在线日韩在线| 日韩视频在线观看| 欧美a级一区二区| 校园春色综合网| 一区二区电影免费观看| 精品成人久久| 国产精品专区一| 欧美日韩精品欧美日韩精品一 | 午夜在线成人av| 亚洲乱码国产乱码精品精98午夜| 久久精品日产第一区二区三区 | 国语自产偷拍精品视频偷| 欧美日韩精品在线视频| 久久午夜电影网| 亚洲欧美中文字幕| 一本色道久久综合亚洲精品小说| 欧美国产在线观看| 久久国产一区| 欧美夜福利tv在线| 亚洲欧美另类在线| 亚洲图片自拍偷拍| 一本色道久久99精品综合| 伊人久久大香线蕉综合热线| 国产日韩精品视频一区| 国产精品久久久久久久7电影| 欧美精品一卡| 欧美精品三级日韩久久| 欧美ab在线视频| 老司机67194精品线观看| 久久久久99精品国产片| 欧美中文字幕在线观看| 欧美亚洲色图校园春色| 亚洲一级在线| 午夜精品久久久久久久99热浪潮| 亚洲视频第一页| 亚洲一区影院| 亚洲欧美日本日韩| 午夜精品区一区二区三| 欧美伊人久久久久久午夜久久久久| 亚洲欧美日韩国产成人精品影院 | 亚洲最新合集| 亚洲桃花岛网站| 午夜精品久久久久久久99水蜜桃| 亚洲欧美日韩区| 久久精品国产第一区二区三区| 久久久国产亚洲精品| 免费一级欧美片在线观看| 欧美激情亚洲| 国产精品普通话对白| 国产亚洲精品久久久久久| 在线播放亚洲| 一区二区三区三区在线| 欧美一区二区三区免费视| 久久亚洲精品伦理| 亚洲激情黄色| 午夜精品久久久久久久久久久久久 | 亚洲一区二区在线播放| 久久精品动漫| 亚洲高清久久| 亚洲在线日韩| 葵司免费一区二区三区四区五区| 欧美日本乱大交xxxxx| 国产精品日本精品| 在线观看视频欧美| 中文亚洲字幕| 久久艳片www.17c.com| 亚洲精品网站在线播放gif| 亚洲一区二区欧美日韩| 久久视频在线看| 国产精品久久久久影院色老大| 国产亚洲精品aa| 亚洲精品国产精品国自产观看 | 亚洲国产一区二区在线| 国产精品99久久久久久人| 久久精彩免费视频| 亚洲国产精品免费| 亚洲综合色噜噜狠狠| 欧美成年人网站| 国产自产精品| 亚洲综合欧美| 亚洲国产精品综合| 欧美一区二区久久久| 欧美日韩精品免费观看视一区二区| 国产综合色精品一区二区三区| 亚洲色图综合久久| 亚洲国产精品t66y| 久久久久久亚洲精品杨幂换脸|