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

正文內(nèi)容

c面向?qū)ο蟪绦蛟O(shè)計(jì)習(xí)題答案-資料下載頁(yè)

2025-06-28 08:02本頁(yè)面
  

【正文】 string arr4[N]={ Hello,Good,Morning,Afternoon,Student,Teacher,School,Company}。 cout排序前:\n。 print(arr4,N)。 bubble_sort(arr4,N)。 cout排序后:\n。 print(arr4,N)。 return 0。}5.【程序參考代碼】include iostream //包含頭文件命令using namespace std。 //使用名字空間stdinclude stringint main(){ string s,s1。 char *ps,*pe, t 。 int i,j,len。 coutPlease input a string:endl。 cins。 s1 = s。 len = ()。 for(i = 0。 i len 1。 i++) { ps = pe = amp。s1[i]。 for(j = i+1。 j len。 j++) { if(*pe s1[j]) pe = amp。s1[j]。 } if(ps != pe) { t = *ps。 *ps = *pe。 *pe = t。 } } couts1endl。 return 0。}6.【程序參考代碼】include iostream //包含頭文件命令using namespace std。 //使用名字空間stdinclude stringvoid total(string s)。int main(){ string s = fas212322@dfs3%。 total(s)。 return 0。}void total(string s){ int characters = 0, digits = 0, other = 0。 for(int i=0。i()。i++) { if((s[i]64amp。amp。s[i]91) ||( s[i]96 amp。amp。 s[i]123)) { characters++。 } else if(s[i]47 amp。amp。s[i]58) { digits++。 } else{ other++。 } } cout字母?jìng)€(gè)數(shù)charactersendl。 cout數(shù)字個(gè)數(shù)digitsendl。 cout其他字符個(gè)數(shù)otherendl。}第3章 類和對(duì)象一、簡(jiǎn)答題1. 【答案要點(diǎn)】 對(duì)象就是封裝了數(shù)據(jù)及在這些數(shù)據(jù)之上的操作的封裝體,這個(gè)封裝體有一個(gè)名字標(biāo)識(shí)它,而且可以向外界提供一組操作(或服務(wù))。類是對(duì)具有相同屬性和操作的一組對(duì)象的抽象描述。類和對(duì)象的關(guān)系:類代表了一組對(duì)象的共性和特征,是對(duì)象的抽象,即類忽略對(duì)象中具體的屬性值而只保留屬性。而對(duì)象是對(duì)類的實(shí)例化,即將類中的屬性賦以具體的屬性值得到一個(gè)具體的對(duì)象。類和對(duì)象的關(guān)系就像圖紙和房屋的關(guān)系,類就像圖紙,而對(duì)象就好比按照?qǐng)D紙建造的房屋。在C++中,類是一種自定義的數(shù)據(jù)類型,而對(duì)象是“類”類型的變量。2. 【答案要點(diǎn)】類中的成員有兩種:數(shù)據(jù)成員和成員函數(shù)。它們的訪問(wèn)屬性有三種:私有的(private)、受保護(hù)的(protected)、公用的(public)。訪問(wèn)屬性為私有的成員只能被本類的成員函數(shù)訪問(wèn)而不能被類外訪問(wèn)(友元例外)。訪問(wèn)屬性為公用的成員既可以被本類的成員函數(shù)訪問(wèn),也可以在類的作用域內(nèi)被其他函數(shù)訪問(wèn)。訪問(wèn)屬性為受保護(hù)的成員可以被本類及本類的派生類的成員函數(shù)訪問(wèn),但不能被類外訪問(wèn)。3. 【答案要點(diǎn)】構(gòu)造函數(shù)是類的一個(gè)特殊的成員函數(shù),構(gòu)造函數(shù)的作用是在創(chuàng)建對(duì)象時(shí)對(duì)對(duì)象的數(shù)據(jù)成員進(jìn)行初始化。析構(gòu)函數(shù)是和構(gòu)造函數(shù)相對(duì)的另一個(gè)類的特殊成員函數(shù),它的作用與構(gòu)造函數(shù)正好相反。析構(gòu)函數(shù)的作用是在系統(tǒng)釋放對(duì)象占用的內(nèi)存之前進(jìn)行一些清理工作。當(dāng)創(chuàng)建對(duì)象時(shí)調(diào)用構(gòu)造函數(shù),當(dāng)釋放對(duì)象時(shí)調(diào)用析構(gòu)函數(shù)。創(chuàng)建對(duì)象是當(dāng)程序執(zhí)行到了非靜態(tài)對(duì)象的定義語(yǔ)句或第一次執(zhí)行到靜態(tài)對(duì)象的定義語(yǔ)句。釋放對(duì)象則是對(duì)象到了生命周期的最后時(shí)系統(tǒng)釋放對(duì)象或通過(guò)delete運(yùn)算符動(dòng)態(tài)釋放new運(yùn)算符動(dòng)態(tài)申請(qǐng)的對(duì)象。最終確定何時(shí)調(diào)用構(gòu)造函數(shù)和析構(gòu)函數(shù)要綜合考慮對(duì)象的作用域、存儲(chǔ)類別等等因素,系統(tǒng)對(duì)對(duì)象這些因素的處理和普通變量是一樣的。4. 【答案要點(diǎn)】對(duì)象的賦值是把一個(gè)對(duì)象的數(shù)據(jù)成員的值賦給另外一個(gè)同類對(duì)象的對(duì)應(yīng)數(shù)據(jù)成員,這兩個(gè)對(duì)象必須是已經(jīng)存在的同類對(duì)象。對(duì)象的復(fù)制是在創(chuàng)建一個(gè)新對(duì)象時(shí)使用一個(gè)已有對(duì)象快速?gòu)?fù)制出完全相同的對(duì)象。對(duì)象的賦值和對(duì)象的復(fù)制的不同點(diǎn)主要有:(1)對(duì)象的賦值是在兩個(gè)對(duì)象都已經(jīng)創(chuàng)建的基礎(chǔ)上進(jìn)行的;而對(duì)象的復(fù)制則在用一個(gè)已有對(duì)象復(fù)制一個(gè)新對(duì)象時(shí)進(jìn)行的。(2)它們兩個(gè)所對(duì)應(yīng)調(diào)用的函數(shù)不同,對(duì)象的賦值系統(tǒng)調(diào)用的是賦值運(yùn)算符重載函數(shù);而對(duì)象的復(fù)制系統(tǒng)調(diào)用的是復(fù)制構(gòu)造函數(shù)。二、寫(xiě)出程序的運(yùn)行結(jié)果Rect (1,1) is constructed!Rect (1,1) is constructed!Rect (1,1) is constructed!Destructor of Rect (1,1) is called!Destructor of Rect (1,1) is called!Destructor of Rect (1,1) is called!三、編程題1.【程序參考代碼】include iostream //包含頭文件命令using namespace std。 //使用名字空間stdclass Box{public: int GetLength(){ return length。 } //獲取長(zhǎng)方體的長(zhǎng)度 int GetWidth() { return width。 } //獲取長(zhǎng)方體的寬度 int GetHeight(){ return height。 } //獲取長(zhǎng)方體的高度 void SetLength(int length){ thislength = length。 }//修改長(zhǎng)方體的長(zhǎng)度 void SetWidth(int width){ thiswidth = width。 } //修改長(zhǎng)方體的寬度 void SetHeight(int height){ thisheight = height。 }//修改長(zhǎng)方體的高度 int GetArea(){ return 2*(length * width + length * height + width * height)。 }//計(jì)算長(zhǎng)方體的表面積 int GetVolume(){ return length * width * height。 } //計(jì)算長(zhǎng)方體的體積private: int length, width, height。//長(zhǎng)方體的長(zhǎng)、寬、高}。int main(){ Box box。 (5)。 (3)。 (4)。 coutThe area of box is: ()endl。 coutThe volume of box is: ()endl。 return 0。}2.【程序參考代碼】include iostream //包含頭文件命令using namespace std。 //使用名字空間stdclass Box{public: Box(){ length=1。 width=1。 height=1。 } //默認(rèn)構(gòu)造函數(shù) Box(int length, int width, int height): length(length), width(width), height(height){} //普通構(gòu)造函數(shù) int GetLength(){ return length。 } //獲取長(zhǎng)方體的長(zhǎng)度 int GetWidth() { return width。 } //獲取長(zhǎng)方體的寬度 int GetHeight(){ return height。 } //獲取長(zhǎng)方體的高度 void SetLength(int length){ thislength = length。 }//修改長(zhǎng)方體的長(zhǎng)度 void SetWidth(int width){ thiswidth = width。 } //修改長(zhǎng)方體的寬度 void SetHeight(int height){ thisheight = height。 }//修改長(zhǎng)方體的高度 int GetArea(){ return 2*(length * width + length * height + width * height)。 }//計(jì)算長(zhǎng)方體的表面積 int GetVolume(){ return length * width * height。 } //計(jì)算長(zhǎng)方體的體積private: int length, width, height。//長(zhǎng)方體的長(zhǎng)、寬、高}。int main(){ Box box1, box 2(2,1,3)。 (5)。 (3)。 (4)。 coutThe area of box1 is: ()endl。 coutThe volume of box1 is: ()endl。 coutThe area of box2 is: ()endl。 coutThe volume of box2 is: ()endl。 return 0。}3.【程序參考代碼】include iostream //包含頭文件命令using namespace std。 //使用名字空間stdclass Box{public: Box(){ length=1。 width=1。 height=1。 } //默認(rèn)構(gòu)造函數(shù) Box(int length, int width, int height): length(length), width(width), height(height){} //普通構(gòu)造函數(shù) int GetLength(){ return length。 } //獲取長(zhǎng)方體的長(zhǎng)度 int GetWidth() { return width。 } //獲取長(zhǎng)方體的寬度 int GetHeight(){ return height。 } //獲取長(zhǎng)方體的高度 void SetLength(int length){ thislength = length。 }//修改長(zhǎng)方體的長(zhǎng)度 void SetWidth(int width){ thiswidth = width。 } //修改長(zhǎng)方體的寬度 void SetHeight(int height){ thisheight = height。 }//修改長(zhǎng)方體的高度 int GetArea(){ return 2*(length * width + length * height + width * height)。 }//計(jì)算長(zhǎng)方體的表面積 int GetVolume(){ return length * width * height。 } //計(jì)算長(zhǎng)方體的體積private: int length, width, height。//長(zhǎng)方體的長(zhǎng)、寬、高}。int main(){ Box *pBox。 pBox = new Box(4,3,2)。 coutThe area of cube is: pBoxGetArea()endl。 delete pBox。 return 0。}4.【程序參考代碼】include iostreamusing namespace std。include stringclass Account{public: Account(string Id, double b)。 //構(gòu)造函數(shù) string getId()。 //獲取賬號(hào) double getBalance()。 //返回當(dāng)前賬戶余額 void deposit(double amount)。 //存款操作 bool withdraw(double amount)。 //取款操作private: string id。 double balance。}。string Account::getId(){return id。}double Account::getBalance(){return balance。}Account::Account(string Id, double Balance){ id=Id。 balance=Balance。}void Account::deposit(double amount)
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評(píng)公示相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1