搜档网
当前位置:搜档网 › C++大学教程(第五版)课后答案 CH1

C++大学教程(第五版)课后答案 CH1

2C h a p t e r 1I n tr od u c t ion t o C omp ut e rs, t he I n t e r ne t a nd W e b

S elf-R e v ie w E x e r c i s e s

1.1F ill in t he b l a nk s in e ac h of t he follo w ing:

a)T he c omp a n y t h a t pop u l a r i z ed pe rs on a l c omp ut ing w a s .

ANS:A pple.

b)T he c omp ut e r t h a t m a de pe rs on a l c omp ut ing legi t im a t e in b us ine ss a nd ind ustry w a s

t he.

ANS:IBM P e rs on a l C omp ut e r.

c)C omp ut e rs p r o c e ss d a t a u nde r t he c on tr ol of s e ts of in stru c t ion s ca lled c omp ut e r

.

ANS:p r og r a m s.

d)T he s i x ke y logi ca l u ni ts of t he c omp ut e r a r e t he,,

,,a nd t he.

ANS:inp ut u ni t,o ut p ut u ni t,memo ry u ni t,a r i t hme t i c a nd logi c u ni t,c en tr a l p r o c e ss ing u ni t, s e c ond a ry st o r a ge u ni t.

e)T he t h r ee c l a ss e s of l a ng u a ge s di s c uss ed in t he c h a p t e r a r e,,

a nd.

ANS:m ac hine l a ng u a ge s,a ss em b l y l a ng u a ge s,high-le v el l a ng u a ge s.

f)T he p r og r a m s t h a t tr a n s l a t e high-le v el l a ng u a ge p r og r a m s in t o m ac hine l a ng u a ge a r e

ca lled.

ANS:c ompile rs.

g)C i s w idel y kno w n a s t he de v elopmen t l a ng u a ge of t he ope r a t ing syst em.

ANS:UNIX.

h)T he l a ng u a ge w a s de v eloped b y W i rt h fo r t e ac hing stru c tur ed p r og r a mming.

ANS:Pa s ca l.

i)T he D ep a rt men t of D efen s e de v eloped t he A d a l a ng u a ge w i t h a ca p ab ili ty ca lled

, w hi c h a llo ws p r og r a mme rs t o s pe c if y t h a t m a n y ac t i v i t ie s ca n p r o c eed in p a r a llel.

ANS:m u l t i t a s king.

1.2F ill in t he b l a nk s in e ac h of t he follo w ing s en t en c e s ab o ut t he C++en v i r onmen t.

a)C++p r og r a m s a r e no r m a ll y ty ped in t o a c omp ut e r us ing a(n)p r og r a m.

ANS:edi t o r.

b)I n a C++ syst em,a(n)p r og r a m e x e c ut e s b efo r e t he c ompile r’s tr a n s l a t ion

ph a s e b egin s.

ANS:p r ep r o c e ss o r.

c)T he p r og r a m c om b ine s t he o ut p ut of t he c ompile r w i t h v a r io us li b r a ry

f u n c t ion s t o p r od u c e a n e x e c ut ab le im a ge.

ANS:linke r.

d)T he p r og r a m tr a n s fe rs t he e x e c ut ab le im a ge of a C++p r og r a m f r om di s k

t o memo ry.

ANS:lo a de r.

1.3F ill in t he b l a nk s in e ac h of t he follo w ing st a t emen ts (ba s ed on S e c t ion1.17):

a)Ob je c ts h a v e t he p r ope rty of—a l t ho u gh o b je c ts m a y kno w ho w t o c om-

m u ni ca t e w i t h one a no t he r ac r o ss w ell-defined in t e r f ac e s, t he y no r m a ll y a r e no t a llo w ed

t o kno w ho w o t he r o b je c ts a r e implemen t ed.

ANS:info r m a t ion hiding.

b)C++p r og r a mme rs c on c en tr a t e on c r e a t ing, w hi c h c on t a in d a t a mem b e rs

a nd t he mem

b e r f u n

c t ion s t h a t m a nip u l a t e t ho s e

d a t a mem b

e rs a nd p r o v ide s e rv i c e s t o

c lien ts.

ANS:c l a ss e s.

S ol ut ion s3

c)C l a ss e s ca n h a v e r el a t ion s hip s w i t h o t he r c l a ss e s.T he s e r el a t ion s hip s a r e ca lled

.

ANS:a ss o c i a t ion s.

d)T he p r o c e ss of a n a l yz ing a nd de s igning a syst em f r om a n o b je c t-o r ien t ed poin t of v ie w

i s ca lled.

ANS:o b je c t-o r ien t ed a n a l ys i s a nd de s ign(OOAD).

e)OOD a l s o t a ke s a d v a n t a ge of r el a t ion s hip s, w he r e ne w c l a ss e s of o b je c ts

a r e de r i v ed

b y ab s o r b ing

c h a r ac t e r i st i c s of e x i st ing c l a ss e s t hen a dding u niq u e c h a r ac-

t e r i st i c s of t hei r o w n.

ANS:inhe r i t a n c e.

f)i s a g r a phi ca l l a ng u a ge t h a t a llo ws people w ho de s ign s of tw a r e syst em s t o

us e a n ind ustry-st a nd a r d no t a t ion t o r ep r e s en t t hem.

ANS:T he U nified M odeling La ng u a ge(UML).

g)T he s i z e, s h a pe,c olo r a nd w eigh t of a n o b je c t a r e c on s ide r ed of t he o b je c t.

ANS:a ttr i b ut e s.

S ol ut ion s

1.4Ca t ego r i z e e ac h of t he follo w ing i t em s a s ei t he r h a r d w a r e o r s of tw a r e:

a)CPU

ANS:h a r d w a r e.

b)C++c ompile r

ANS:s of tw a r e.

c)ALU

ANS:h a r d w a r e.

d)C++p r ep r o c e ss o r

ANS:s of tw a r e.

e)inp ut u ni t

ANS:h a r d w a r e.

f)a n edi t o r p r og r a m

ANS:s of tw a r e.

1.5W h y migh t y o u w a n t t o wr i t e a p r og r a m in a m ac hine-independen t l a ng u a ge in st e a d of a m ac hine-dependen t l a ng u a ge?W h y migh t a m ac hine-dependen t l a ng u a ge b e mo r e a pp r op r i a t e fo r wr i t ing c e rt a in ty pe s of p r og r a m s?

ANS:Mac hine independen t l a ng u a ge s a r e us ef u l fo r wr i t ing p r og r a m s t o b e e x e c ut ed on m u l t iple c omp ut e r pl a t fo r m s.Mac hine dependen t l a ng u a ge s a r e a pp r op r i a t e fo r

wr i t ing p r og r a m s t o b e e x e c ut ed on a s ingle pl a t fo r m.

1.6F ill in t he b l a nk s in e ac h of t he follo w ing st a t emen ts:

a)W hi c h logi ca l u ni t of t he c omp ut e r r e c ei v e s info r m a t ion f r om o uts ide t he c omp ut e r fo r

us e b y t he c omp ut e r?.

ANS:inp ut u ni t.

b)T he p r o c e ss of in stru c t ing t he c omp ut e r t o s ol v e s pe c ifi c p r o b lem s i s ca lled

.

ANS:c omp ut e r p r og r a mming.

c)W h a t ty pe of c omp ut e r l a ng u a ge us e s E ngli s h-like abb r e v i a t ion s fo r m ac hine l a ng u a ge

in stru c t ion s?.

ANS:a ss em b l y l a ng u a ge.

4C h a p t e r 1I n tr od u c t ion t o C omp ut e rs, t he I n t e r ne t a nd W e b

d)W hi c h logi ca l u ni t of t he c omp ut e r s end s info r m a t ion t h a t h a s a l r e a d y b een p r o c e ss ed

b y t he

c omp ut e r t o v a r io us de v i c e s s o t h a t t he info r m a t ion m a y b e us e

d o uts id

e t he

c omp ut e r?.

ANS:o ut p ut u ni t.

e)W hi c h logi ca l u ni t of t he c omp ut e r r e t a in s info r m a t ion?.

ANS:memo ry u ni t a nd s e c ond a ry st o r a ge u ni t.

f)W hi c h logi ca l u ni t of t he c omp ut e r pe r fo r m s ca l c u l a t ion s?.

ANS:a r i t hme t i c a nd logi ca l u ni t.

g)W hi c h logi ca l u ni t of t he c omp ut e r m a ke s logi ca l de c i s ion s?.

ANS:a r i t hme t i c a nd logi ca l u ni t.

h)T he le v el of c omp ut e r l a ng u a ge mo st c on v enien t t o t he p r og r a mme r fo r wr i t ing p r o-

g r a m s q u i c kl y a nd e a s il y i s .

ANS:high-le v el l a ng u a ge.

i)T he onl y l a ng u a ge t h a t a c omp ut e r di r e c t l y u nde rst a nd s i s ca lled t h a t c omp ut e r's

.

ANS:m ac hine l a ng u a ge.

j)W hi c h logi ca l u ni t of t he c omp ut e r c oo r din a t e s t he ac t i v i t ie s of a ll t he o t he r logi ca l u ni ts?.

ANS:c en tr a l p r o c e ss ing u ni t.

1.7W h y i s s o m u c h a tt en t ion t od a y fo c us ed on o b je c t-o r ien t ed p r og r a mming in gene r a l a nd C++in p a rt i c u l a r?

ANS:Ob je c t-o r ien t ed p r og r a mming en ab le s t he p r og r a mme r t o b u ild r e us ab le s of tw a r e

c omponen ts t h a t model i t em s in t he r e a l w o r ld.B u ilding s of tw a r e q u i c kl y,c o rr e c t l y,

a nd e c onomi ca ll y h a s

b een a n el us i v e go a l in t he s of tw a r e ind ustry.T he mod u l a r,o b-

je c t-o r ien t ed de s ign a nd implemen t a t ion a pp r o ac h h a s b een fo u nd t o in c r e a s e p r o-

d u c t i v i ty w hil

e r ed u c ing de v elopmen t t ime,e rr o rs,a nd c o st.

1.8D i st ing u i s h b e tw een t he t e r m s f a t a l e rr o r a nd nonf a t a l e rr o r.W h y migh t y o u p r efe r t o e x-pe r ien c e a f a t a l e rr o r r a t he r t h a n a nonf a t a l e rr o r?

ANS:A f a t a l e rr o r ca us e s a p r og r a m t o t e r min a t e p r em a tur el y.A nonf a t a l e rr o r o cc urs w hen t he logi c of t he p r og r a m i s in c o rr e c t,a nd t he p r og r a m doe s no t w o r k p r ope r l y.A f a t a l

e rr o r i s p r efe rr ed fo r de b u gging p ur po s e s.A

f a t a l e rr o r immedi a t el y le ts y o u kno w

t he r e i s a p r o b lem w i t h t he p r og r a m, w he r e a s a nonf a t a l e rr o r ca n b e su b t le a nd po s-

s i b l y go u nde t e c t ed.

1.9G i v e a b r ief a n sw e r t o e ac h of t he follo w ing q u e st ion s:

a)W h y doe s t hi s t e xt di s c uss stru c tur ed p r og r a mming in a ddi t ion t o o b je c t-o r ien t ed p r o-

g r a mming?

ANS:Ob je c ts a r e c ompo s ed in p a rt b y stru c tur ed p r og r a m pie c e s.

b)W h a t a r e t he ty pi ca l st ep s (men t ioned in t he t e xt)of a n o b je c t-o r ien t ed de s ign p r o c e ss?

ANS:(1)D e t e r mine w hi c h o b je c ts a r e needed t o implemen t t he syst em.(2)D e t e r mine

e ac h o b je c t’s a ttr i b ut e s.(3)D e t e r mine e ac h o b je c t’s b eh a v io rs.(4)D e t e r mine t he in-

t e r ac t ion b e tw een t he o b je c ts.

c)W h a t kind s of me ss a ge s do people s end t o one a no t he r?

ANS:P eople s end me ss a ge s t h r o u gh b od y l a ng u a ge, s pee c h, wr i t ing s,e-m a il, t elephone s,

e t c.

d)Ob je c ts s end me ss a ge s t o one a no t he r ac r o ss w ell-defined in t e r f ac e s.W h a t in t e r f ac e s

doe s a ca r r a dio(o b je c t)p r e s en t t o i ts us e r (a pe rs on o b je c t)?

ANS:D i a l s a nd b utt on s t h a t a llo w t he us e r t o s ele c t a st a t ion,a dj ust t he v ol u me,a dj ust ba ss

a nd tr e

b le,pl a y a CD o r t a pe,e t c.

S ol ut ion s5

1.10Y o u a r e p r o bab l y w e a r ing on y o ur wr i st one of t he w o r ld’s mo st c ommon ty pe s of o b je c ts—

a w a t c h.D i s c uss ho w e ac h of t he follo w ing t e r m s a nd c on c ep ts a pplie s t o t he no t ion of a w a t c h:o

b je

c t, a ttr i b ut e s,b eh a v io rs,c l a ss,inhe r i t a n c e(c on s ide r,fo r e x a mple,a n a l a r m c lo c k),ab str ac t ion,modeling, me ss a ge s,en ca p su l a t ion,in t e r f ac e,info r m a t ion hiding,

d a t a mem b

e rs a nd mem b e r

f u n c t ion s.

ANS:T he en t i r e w a t c h i s a n o b je c t t h a t i s c ompo s ed of m a n y o t he r o b je c ts (su c h a s t he mo v ing p a rts, t he ba nd, t he f ac e,e t c.)Wa t c h a ttr i b ut e s a r e t ime,c olo r,ba nd, sty le

(digi t a l o r a n a log),e t c.T he b eh a v io rs of t he w a t c h in c l u de s e tt ing t he t ime a nd ge t-

t ing t he t ime.A w a t c h ca n b e c on s ide r ed a s pe c ifi c ty pe of c lo c k(a s ca n a n a l a r m

c lo c k).W i t h t h a t in mind,i t i s po ss i b le t h a t a c l a ss ca lle

d C lo c k c o u ld

e x i st

f r om

w hi c h o t he r c l a ss e s su c h a s w a t c h a nd a l a r m c lo c k ca n inhe r i t t he ba s i c fe a tur e s in t he

c lo c k.T he w a t c h i s a n ab str ac t ion of t he me c h a ni c s neede

d t o keep tr ac k of t h

e t ime.

T he us e r of t he w a t c h doe s no t need t o kno w t he me c h a ni c s of t he w a t c h in o r de r t o

us e i t; t he us e r onl y need s t o kno w t h a t t he w a t c h keep s t he p r ope r t ime.I n t hi s s en s e,

t he me c h a ni c s of t he w a t c h a r e en ca p su l a t ed(hidden)in s ide t he w a t c h.T he in t e r f ac e

t o t he w a t c h(i ts f ac e a nd c on tr ol s fo r s e tt ing t he t ime)a llo ws t he us e r t o s e t a nd ge t

t he t ime.T he us e r i s no t a llo w ed t o di r e c t l y t o u c h t he in t e r n a l me c h a ni c s of t he

w a t c h.A ll in t e r ac t ion w i t h t he in t e r n a l me c h a ni c s i s c on tr olled b y t he in t e r f ac e t o t he

w a t c h.T he d a t a mem b e rs st o r ed in t he w a t c h a r e hidden in s ide t he w a t c h a nd t he

mem b e r f u n c t ion s (looking a t t he f ac e t o ge t t he t ime a nd s e tt ing t he t ime)p r o v ide

t he in t e r f ac e t o t he d a t a.

相关主题