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

正文內(nèi)容

c面向對象程序設計習題答案-資料下載頁

2025-06-28 08:02本頁面
  

【正文】 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字母個數(shù)charactersendl。 cout數(shù)字個數(shù)digitsendl。 cout其他字符個數(shù)otherendl。}第3章 類和對象一、簡答題1. 【答案要點】 對象就是封裝了數(shù)據(jù)及在這些數(shù)據(jù)之上的操作的封裝體,這個封裝體有一個名字標識它,而且可以向外界提供一組操作(或服務)。類是對具有相同屬性和操作的一組對象的抽象描述。類和對象的關系:類代表了一組對象的共性和特征,是對象的抽象,即類忽略對象中具體的屬性值而只保留屬性。而對象是對類的實例化,即將類中的屬性賦以具體的屬性值得到一個具體的對象。類和對象的關系就像圖紙和房屋的關系,類就像圖紙,而對象就好比按照圖紙建造的房屋。在C++中,類是一種自定義的數(shù)據(jù)類型,而對象是“類”類型的變量。2. 【答案要點】類中的成員有兩種:數(shù)據(jù)成員和成員函數(shù)。它們的訪問屬性有三種:私有的(private)、受保護的(protected)、公用的(public)。訪問屬性為私有的成員只能被本類的成員函數(shù)訪問而不能被類外訪問(友元例外)。訪問屬性為公用的成員既可以被本類的成員函數(shù)訪問,也可以在類的作用域內(nèi)被其他函數(shù)訪問。訪問屬性為受保護的成員可以被本類及本類的派生類的成員函數(shù)訪問,但不能被類外訪問。3. 【答案要點】構造函數(shù)是類的一個特殊的成員函數(shù),構造函數(shù)的作用是在創(chuàng)建對象時對對象的數(shù)據(jù)成員進行初始化。析構函數(shù)是和構造函數(shù)相對的另一個類的特殊成員函數(shù),它的作用與構造函數(shù)正好相反。析構函數(shù)的作用是在系統(tǒng)釋放對象占用的內(nèi)存之前進行一些清理工作。當創(chuàng)建對象時調(diào)用構造函數(shù),當釋放對象時調(diào)用析構函數(shù)。創(chuàng)建對象是當程序執(zhí)行到了非靜態(tài)對象的定義語句或第一次執(zhí)行到靜態(tài)對象的定義語句。釋放對象則是對象到了生命周期的最后時系統(tǒng)釋放對象或通過delete運算符動態(tài)釋放new運算符動態(tài)申請的對象。最終確定何時調(diào)用構造函數(shù)和析構函數(shù)要綜合考慮對象的作用域、存儲類別等等因素,系統(tǒng)對對象這些因素的處理和普通變量是一樣的。4. 【答案要點】對象的賦值是把一個對象的數(shù)據(jù)成員的值賦給另外一個同類對象的對應數(shù)據(jù)成員,這兩個對象必須是已經(jīng)存在的同類對象。對象的復制是在創(chuàng)建一個新對象時使用一個已有對象快速復制出完全相同的對象。對象的賦值和對象的復制的不同點主要有:(1)對象的賦值是在兩個對象都已經(jīng)創(chuàng)建的基礎上進行的;而對象的復制則在用一個已有對象復制一個新對象時進行的。(2)它們兩個所對應調(diào)用的函數(shù)不同,對象的賦值系統(tǒng)調(diào)用的是賦值運算符重載函數(shù);而對象的復制系統(tǒng)調(diào)用的是復制構造函數(shù)。二、寫出程序的運行結果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。 } //獲取長方體的長度 int GetWidth() { return width。 } //獲取長方體的寬度 int GetHeight(){ return height。 } //獲取長方體的高度 void SetLength(int length){ thislength = length。 }//修改長方體的長度 void SetWidth(int width){ thiswidth = width。 } //修改長方體的寬度 void SetHeight(int height){ thisheight = height。 }//修改長方體的高度 int GetArea(){ return 2*(length * width + length * height + width * height)。 }//計算長方體的表面積 int GetVolume(){ return length * width * height。 } //計算長方體的體積private: int length, width, height。//長方體的長、寬、高}。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。 } //默認構造函數(shù) Box(int length, int width, int height): length(length), width(width), height(height){} //普通構造函數(shù) int GetLength(){ return length。 } //獲取長方體的長度 int GetWidth() { return width。 } //獲取長方體的寬度 int GetHeight(){ return height。 } //獲取長方體的高度 void SetLength(int length){ thislength = length。 }//修改長方體的長度 void SetWidth(int width){ thiswidth = width。 } //修改長方體的寬度 void SetHeight(int height){ thisheight = height。 }//修改長方體的高度 int GetArea(){ return 2*(length * width + length * height + width * height)。 }//計算長方體的表面積 int GetVolume(){ return length * width * height。 } //計算長方體的體積private: int length, width, height。//長方體的長、寬、高}。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。 } //默認構造函數(shù) Box(int length, int width, int height): length(length), width(width), height(height){} //普通構造函數(shù) int GetLength(){ return length。 } //獲取長方體的長度 int GetWidth() { return width。 } //獲取長方體的寬度 int GetHeight(){ return height。 } //獲取長方體的高度 void SetLength(int length){ thislength = length。 }//修改長方體的長度 void SetWidth(int width){ thiswidth = width。 } //修改長方體的寬度 void SetHeight(int height){ thisheight = height。 }//修改長方體的高度 int GetArea(){ return 2*(length * width + length * height + width * height)。 }//計算長方體的表面積 int GetVolume(){ return length * width * height。 } //計算長方體的體積private: int length, width, height。//長方體的長、寬、高}。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)。 //構造函數(shù) string getId()。 //獲取賬號 double getBalance()。 //返回當前賬戶余額 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)
點擊復制文檔內(nèi)容
環(huán)評公示相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1