freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

面向?qū)ο蟪绦蛟O(shè)計(jì)c課后題答案-閱讀頁(yè)

2025-07-08 01:29本頁(yè)面
  

【正文】 之前的所有全局變量都是在main()開(kāi)始之前就建立了的。 [4_16] [4_17]構(gòu)建一個(gè)類(lèi)book,其中含有2個(gè)私有數(shù)據(jù)成員qu和price,建立一個(gè)有5個(gè)元素的數(shù)組對(duì)象,將qu初始化為1~5,將price初始化為qu的10倍。 答案見(jiàn)下:include class book{{ qu=a。 price=b。 } { coutqu*price\n。}。 book ob[5]={ book(1,10),book(2,20),//16題用下面語(yǔ)句/*int i。i5。 return 0。 book *p。ob[4]。i5。 pshow_money()。}return 0。 見(jiàn)書(shū)139頁(yè)題include //include class toy{ price=p。 count=c。 void pute()。private: int price。 long total。void toy::input(int p,int c){ count=c。 total=(long)price*count。 }void toy::print(){ coutprice=price count=count total=total\n。//測(cè)試構(gòu)造函數(shù)i6。 ob[i].pute()。clrscr()。 for(i=0。i++) }[4_19]構(gòu)建一個(gè)類(lèi)stock 見(jiàn)書(shū)139頁(yè) 答案如下:include include include const int SIZE=80。 public: stock() strcpy(stockcode, )。 } { strcpy(stockcode,code)。 price=p。} { int quan。}。 ()。 char stockc[]=600002。 ()。}說(shuō)明:執(zhí)行以下語(yǔ)句,可在定義對(duì)象的同時(shí),給數(shù)據(jù)成員設(shè)置初值。char stockc[]=”600002”。()。 //深圳類(lèi)class shang_stock //上海類(lèi){ public://計(jì)算上海的 //普通股票個(gè)數(shù) int st。 //ST股票個(gè)數(shù) int pt。 //PT股票個(gè)數(shù)}。 general=g。 pt=p。 int general。 //普通股票個(gè)數(shù) int st。 //PT股票個(gè)數(shù)public: shen_stock(int g,int s,int p)。//計(jì)算深圳的股票總數(shù) friend void count(const shang_stock ss,const shen_stock zs)。shen_stock::shen_stock(int g,int s,int p)//構(gòu)造函數(shù){ st=s。}main(){//建立對(duì)象 //表示深圳有1500支股票,15支ST股票,8支PT股票 shang_count(shanghai)。//計(jì)算深圳的股票總數(shù) count(shanghai,shenzhen)。}void shang_count(const shang_stock ss)//計(jì)算上海的股票總數(shù){ int s。 coutstocks of shanghai are ++endl。 }void count(const shang_stock ss,const shen_stock es) //計(jì)算上海和深圳的股票總數(shù){ int s。 s=+++++。 coutstocks of shanghai and shenzhen sendl。(1)基類(lèi)中的私有成員無(wú)論哪種繼承方式,基類(lèi)中的私有成員不允許派生類(lèi)繼承,即在派生類(lèi)中是不可直接訪(fǎng)問(wèn)的。 (3)基類(lèi)中的保護(hù)成員 當(dāng)類(lèi)的繼承方式為公有繼承時(shí),基類(lèi)中的所有保護(hù)成員在派生類(lèi)中仍以保護(hù)成員的身份出現(xiàn);當(dāng)類(lèi)的繼承方式為私有繼承時(shí),基類(lèi)中的所有保護(hù)成員在派生類(lèi)中都是以私有成員的身份出現(xiàn):當(dāng)類(lèi)的繼承方式為保護(hù)繼承時(shí),基類(lèi)中的所有保護(hù)成員在派生類(lèi)中仍以保護(hù)成員的身份出現(xiàn)。因此,為了便于派生類(lèi)的訪(fǎng)問(wèn),可以將基類(lèi)私有成員中需要提供給派生類(lèi)訪(fǎng)問(wèn)的成員定義為保護(hù)成員。[5_4]答:通常情況下,當(dāng)創(chuàng)建派生類(lèi)對(duì)象時(shí),首先執(zhí)行基類(lèi)的構(gòu)造函數(shù),隨后再執(zhí)行派生類(lèi)的構(gòu)造函數(shù);當(dāng)撤消派生類(lèi)對(duì)象時(shí),則先執(zhí)行派生類(lèi)的析構(gòu)函數(shù)函數(shù),隨后再執(zhí)行基類(lèi)的析構(gòu)函數(shù)。當(dāng)基類(lèi)含有帶參數(shù)的構(gòu)造函數(shù)時(shí),派生類(lèi)必須定義構(gòu)造函數(shù),以提供把參數(shù)傳遞給基類(lèi)構(gòu)造函數(shù)的途徑。 }其中基類(lèi)構(gòu)造函數(shù)的參數(shù),通常來(lái)源于派生類(lèi)構(gòu)造函數(shù)的參數(shù)表,也可以用常數(shù)值。[5_6]答:當(dāng)一個(gè)派生類(lèi)具有多個(gè)基類(lèi)時(shí),這種派生方法稱(chēng)為多繼承。在多個(gè)基類(lèi)之間則嚴(yán)格按照派生類(lèi)聲明時(shí)從左到右的順序來(lái)排列先后。[5_7]在類(lèi)的派生中為何要引入虛基類(lèi)?虛基類(lèi)構(gòu)造函數(shù)的調(diào)用順序是如何規(guī)定的?當(dāng)引用派生類(lèi)的成員時(shí),首先在派生類(lèi)自身的作用域中尋找這個(gè)成員,如果沒(méi)有找到,則到它的基類(lèi)中尋找。為了解決這種二義性,C++引入了虛基類(lèi)的概念。(2)若虛基類(lèi)由非虛基類(lèi)派生而來(lái),則仍然先調(diào)用基類(lèi)構(gòu)造函數(shù),再調(diào)用派生類(lèi)的構(gòu)造函數(shù)。[5_8]答:A[5_9]答:C[5_10]答:C[5_11]答:C 說(shuō)明:set_price()和print_price()在派生類(lèi)中是私有成員函數(shù),不能被派生類(lèi)對(duì)象直接訪(fǎng)問(wèn),所以A和D是錯(cuò)誤的。[5_12]答:B 說(shuō)明:code是私有數(shù)據(jù)成員,不能直接存取,所以B是錯(cuò)誤的。當(dāng)類(lèi)SideLine的構(gòu)造函數(shù)調(diào)用了虛基類(lèi)Person的構(gòu)造函數(shù)之后,類(lèi)Student和類(lèi)Employee對(duì)類(lèi)SideLine的構(gòu)造函數(shù)的調(diào)用被忽略了,這是初始化虛基類(lèi)和非虛基類(lèi)不同的地方。[5_14]運(yùn)行結(jié)果是:40 50 10 20 30 40 50 60[5_15]修改后的程序如下:include include class table{public: table(int p,int q) {}。 int k=1。ij。 coutsetw(4)i (char)i。 if((k)%12==0) cout\n。 k++。}class der_table:public table{public: der_table(int p,int q,char *m):table(p,q) {}。 coutc\n。}void main(){a39。z39。 ()。 public: time(int h,int m,int s) hours=h。 minutes=m。 seconds=s。} { }protected: int hours,minutes,seconds。class date{ date(int m,int d,int y) { day=d。 } virtual void display() {}。 public: birthtime(char *,int mm,int dd,int yy,int hh,int mint,int ss):time(hh,mint,ss),date(mm,dd,yy) strcpy(childname,)。 } { 39。 date::display()。 coutendl。 time::display()。}protected: char childname[20]。void main(){ ()。 public: animal() name=NULL。 } {virtual void whoami()。}。 public: cat():animal() } {void whoami()。class tiger:public cat{{ } { } }。 name=new char [strlen(n)+1]。}void animal::whoami(){ couti am a cat name nameendl。 }void tiger::whoami(){ }void main() cat cat(john)。 tiger tiger(richard)。}[5_18]實(shí)現(xiàn)本題功能的程序如下:include class building{ floors=f。 rooms=r。 footage=ft。//層數(shù) int rooms。 //房間數(shù) double footage。class house:public building{ :building(f,r,ft) { bedrooms=br。 bathrooms=bth。 } void show() {\n39。 coutrooms:\n39。 coutsquare footage: footage39。 \n39。 coutbathroorns: bathrooms39。 }private: int bedrooms。//浴室數(shù)}。 public: office(int f,int r,double ft,int p,int ext):building(f,r,ft) phones=p。 extinguishers=ext。 } {\n39。 coutrooms:\n39。 coutsquare footage: footage39。\n39。 coutfire extinguishers: 。 coutextinguishers39。 //電話(huà)數(shù) int extinguishers。main(){ office o_ob(4,25,12000,30,8)。 ()。 ()。}[5_19]實(shí)現(xiàn)本題功能的程序如下:include include const int l=80。 public: void input() cout\n input name: 。 cinname。 cout\n certificate no: 。 cinid。} {void printname() coutsetw(8)name。 }private: char name[l],id[l]。class stud{ public: cout input address: 。 cout input telphone no: 。 } void print() { cout\n address: \taddr。 cout\n telphone no: \ttel。 char tel[l]。class student:private person{{ void print() person::print()。cout\n score no: \tsno。} { unsigned long sno。class score:private student,private stud{{ void print() student::print()。 stud::print()。 cout\n math score: \tmath。 cout\n english svore: \teng。 cout\n average score: \tfloat(math+eng)/2。} { int eng。class teacher:public person{{ void print() person::print()。 cout\n degree: \tdegree。 cout\n department: \tdep。} {}。 score c1。 coutinput data for score 1: 。 coutinput data for teacher 1: 。cout\n data on student 。 ()。1
點(diǎn)擊復(fù)制文檔內(nèi)容
研究報(bào)告相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1