C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx

上传人:b****5 文档编号:19197698 上传时间:2023-01-04 格式:DOCX 页数:23 大小:20.16KB
下载 相关 举报
C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx_第1页
第1页 / 共23页
C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx_第2页
第2页 / 共23页
C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx_第3页
第3页 / 共23页
C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx_第4页
第4页 / 共23页
C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx

《C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx(23页珍藏版)》请在冰豆网上搜索。

C++PrimerPlus第六版第十四章课后习题部分答案Word文档格式.docx

show(inty)const

for(inti=0;

i<

y;

i++)

cout<

<

"

\t\t"

<

years[i]<

\t"

bottles[i]<

endl;

Set(constT1&

t2)

years=t1;

bottles=t2;

typedefvalarray<

int>

ArrayInt;

typedefPair<

ArrayInt,ArrayInt>

PairArray;

classWine

std:

stringwinename;

intyear;

PairArrayout;

Wine(){}

Wine(constchar*l,inty,constintyr[],constintbot[]);

Wine(constchar*l,inty);

voidGetBottle();

string&

Label();

intsum()const;

voidshow()const;

#endif

Wine.cpp

#include"

wine.h"

Wine:

Wine(constchar*l,inty,constintyr[],constintbot[])

winename=l;

year=y;

out.Set(ArrayInt(yr,year),ArrayInt(bot,year));

Wine(constchar*l,inty)

voidWine:

GetBottle()

ArrayIntyr(year),bt(year);

year;

{

Enteryear:

"

;

cin>

>

yr[i];

Enterbottles:

bt[i];

}

out.Set(yr,bt);

intWine:

sum()const

returnout.Sum();

std:

Wine:

Label()

returnwinename;

show()const

cout<

Wine:

winename<

endl;

Year"

Bottle\n"

out.show(year);

Main.cpp

intmain(void)

Enternameofwine:

charlab[50];

cin.getline(lab,50);

Enternumberofyears:

intyrs;

cin>

yrs;

Wineholding(lab,yrs);

holding.GetBottle();

holding.show();

constintYRS=3;

inty[YRS]={1993,1995,1998};

intb[YRS]={48,60,72};

Winemore("

GushingGrapeRED"

YRS,y,b);

more.show();

Totalbottlesfor"

more.Label()<

:

more.sum()<

system("

Pause"

);

return0;

2.

classWine:

privatestring,privatePairArray

return(string&

)*this;

(string&

)*this<

3.无

4.

头文件

cstdlib>

cstring>

classPerson

stringfirstname;

stringlastname;

protected:

virtualvoidData();

virtualvoidGet();

Person():

firstname("

noone"

),lastname("

){}

Person(conststring&

fn,conststring&

ln):

firstname(fn),lastname(ln){}

virtual~Person()=0;

virtualvoidSet()=0;

virtualvoidShow()=0;

classGunslinger:

virtualpublicPerson

intnumber;

voidData();

voidGet();

Gunslinger():

number(0),Person(){}

Gunslinger(conststring&

ln,intn=0):

Person(fn,ln),number(n){}

Gunslinger(Person&

p,intn=0):

Person(p),number(n){}

voidShow();

voidSet();

doubleDraw();

classPokerPlayer:

PokerPlayer():

Person(){}

PokerPlayer(conststring&

Person(fn,ln){}

PokerPlayer(constPerson&

p):

Person(p){}

voidShow();

voidSet(){Person:

Set();

intDraw();

classBadDude:

publicGunslinger,publicPokerPlayer

BadDude(){}

BadDude(intn,conststring&

Person(fn,ln),Gunslinger(fn,ln,n),PokerPlayer(fn,ln){}

BadDude(intn,Person&

Person(p),Gunslinger(p,n),PokerPlayer(p){}

BadDude(Gunslinger&

g):

Person(g),Gunslinger(g),PokerPlayer(g){}

BadDude(intn,PokerPlayer&

po):

Person(po),Gunslinger(po,n),PokerPlayer(po){}

doubleGdraw();

intCdraw();

函数定义

Person:

~Person(){}

voidPerson:

Data()

Firstname:

firstname<

Lastname:

lastname<

Get()

Enterfirstname:

\n"

getline(cin,firstname);

Enterlastname:

getline(cin,lastname);

Set()

Get();

Show()

Data();

voidGunslinger:

Number:

number<

Enternumber:

number;

Gunslinger\n"

Person:

Data();

Get();

doubleGunslinger:

Draw()

returnrand()%2+3;

voidPokerPlayer:

Thecard:

Draw()<

\nPokerPlayer:

\n"

intPokerPlayer:

returnrand()%52+1;

voidBadDude:

Gunslinger:

PokerPlayer:

\nThenextcard:

Cdraw()<

ThetimeofBadDudegetthegun:

Gdraw()<

Get()

doubleBadDude:

Gdraw()

returnGunslinger:

Draw();

intBadDude:

Cdraw()

returnPokerPlayer:

\nBadDude:

Main

constintSIZE=5;

intmain()

Person*lolas[SIZE];

intct;

for(ct=0;

ct<

SIZE;

ct++)

charchoice;

Enterthepersoncategory:

<

g:

Gunslingerp:

PokerPlayer"

<

b:

Baddudeq:

Quit\n"

choice;

while(strchr("

gpbq"

choice)==NULL)

{

cout<

Pleaseenterag,p,b,q:

cin>

}

if(choice=='

q'

break;

switch(choice)

case'

g'

lolas[ct]=newGunslinger;

p'

lolas[ct]=newPokerPlayer;

b'

lolas[ct]=newBadDude;

cin.get();

lolas[ct]->

\nHereisperson:

inti;

ct;

lolas[i]->

Show();

for(i=0;

deletelolas[i];

Done\n"

5.

classabstr_emp

stringfname;

stringlname;

stringjob;

abstr_emp();

abstr_emp(conststd:

fn,conststd:

ln,conststd:

j);

virtual~abstr_emp()=0;

virtualvoidSetall();

virtualvoidShowall()const;

friendstd:

ostream&

operator<

(std:

os,constabstr_emp&

e);

classemployee:

publicabstr_emp

employee();

employee(conststd:

classmanager:

virtualpublicabstr_emp

intinchargeof;

intInChargeOf()const{returninchargeof;

//int&

InChargeOf()const{returninchargeof;

manager();

manager(conststd:

j,intico=0);

manager(constabstr_emp&

e,intico=0);

manager(constmanager&

m);

classfink:

stringreportsto;

conststd:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1