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