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

正文內(nèi)容

第六章數(shù)組指針與字符串-資料下載頁

2025-07-20 23:57本頁面
  

【正文】 e std。 int main() { float (*cp)[9][8]。 int i,j,k。 cp = new float[8][9][8]。 for (i=0。 i8。 i++) for (j=0。 j9。 j++) for (k=0。 k9。 k++) *(*(*(cp+i)+j)+k)=i*100+j*10+k。 //通過指針訪問數(shù)組元素 for (i=0。 i8。 i++) { for (j=0。 j9。 j++) { for (k=0。 k8。 k++) //將指針 cp作為數(shù)組名使用, //通過數(shù)組名和下標(biāo)訪問數(shù)組元素 coutcp[i][j][k] 。 coutendl。 } coutendl。 } } 93 C++語言程序設(shè)計 94 動態(tài)存儲分配函數(shù) ? void *malloc( size )。 參數(shù) size:欲分配的字節(jié)數(shù) 返回值:成功,則返回 void型指針。 失敗,則返回空指針。 頭文件: cstdlib 和 cmalloc C++語言程序設(shè)計 95 動態(tài)內(nèi)存釋放函數(shù) ? void free( void *memblock )。 參數(shù) memblock:指針,指向需釋放的內(nèi)存。 返回值:無 頭文件: cstdlib 和 cmalloc C++語言程序設(shè)計 96 淺拷貝與深拷貝 ? 淺拷貝 實現(xiàn)對象間數(shù)據(jù)元素的一一對應(yīng)復(fù)制。 ? 深拷貝 當(dāng)被復(fù)制的對象數(shù)據(jù)成員是指針類型時,不是復(fù)制該指針成員本身,而是將指針?biāo)傅膶ο筮M行復(fù)制。 淺拷貝與深拷貝 C++語言程序設(shè)計 97 例 620對象的淺拷貝 include iostream using namespace std。 class Point { //類的聲明同例 616 //?? }。 class ArrayOfPoints { //類的聲明同例 618 //?? }。 淺拷貝與深拷貝 int main() { int number。 cinnumber。 ArrayOfPoints pointsArray1(number)。 (0).Move(5,10)。 (1).Move(15,20)。 ArrayOfPoints pointsArray2(pointsArray1)。 coutCopy of pointsArray1:endl。 coutPoint_0 of array2: (0).GetX() , (0).GetY()endl。 coutPoint_1 of array2: (1).GetX() , (1).GetY()endl。 98 (0).Move(25,30)。 (1).Move(35,40)。 coutAfter the moving of pointsArray1:endl。 coutPoint_0 of array2: (0).GetX() , (0).GetY()endl。 coutPoint_1 of array2: (1).GetX() , (1).GetY()endl。 } 99 運行結(jié)果如下: Please enter the number of points:2 Default Constructor called. Default Constructor called. Copy of pointsArray1: Point_0 of array2: 5, 10 Point_1 of array2: 15, 20 After the moving of pointsArray1: Point_0 of array2: 25, 30 Point_1 of array2: 35, 40 Deleting... Destructor called. Destructor called. Deleting... 接下來程序出現(xiàn)異常,也就是運行錯誤。 100 拷貝前 拷貝后 pointsArray1的數(shù)組元素占用的內(nèi)存 points numberOfPoints pointsArray1 points numberOfPoints pointsArray1 pointsArray1的數(shù)組元素占用的內(nèi)存 points numberOfPoints pointsArray2 101 C++語言程序設(shè)計 102 例 621對象的深拷貝 include iostream using namespace std。 class Point { //類的聲明同例 616 ?? }。 class ArrayOfPoints { public: ArrayOfPoints(ArrayOfPointsamp。 pointsArray)。 //其他成員同例 618 }。 淺拷貝與深拷貝 ArrayOfPoints ::ArrayOfPoints (ArrayOfPointsamp。 pointsArray) { numberOfPoints =。 points=new Point[numberOfPoints]。 for (int i=0。 inumberOfPoints。 i++) points[i].Move( (i).GetX(), (i).GetY())。 } int main() { //同例 620 } 103 程序的運行結(jié)果如下: Please enter the number of points:2 Default Constructor called. Default Constructor called. Default Constructor called. Default Constructor called. Copy of pointsArray1: Point_0 of array2: 5, 10 Point_1 of array2: 15, 20 After the moving of pointsArray1: Point_0 of array2: 5, 10 Point_1 of array2: 15, 20 Deleting... Destructor called. Destructor called. Deleting... Destructor called. Destructor called. 104 拷貝前 pointsArray1 的數(shù)組元素占用的內(nèi)存 points numberOfPoints pointsArray1 拷貝后 points numberOfPoints pointsArray1 pointsArray1 的數(shù)組元素占用的內(nèi)存 points numberOfPoints pointsArray2 105 C++語言程序設(shè)計 106 用字符數(shù)組存儲和處理字符串 字符數(shù)組的聲明和引用 例: static char str[8]={112,114,111,103,114,97,109,0}。 //字符 ACSII值 static char str[8]={39。p39。,39。r39。,39。o39。,39。g39。,39。r39。,39。a39。,39。m39。,39。\039。}。 static char str[8]=program。 static char str[]=program。 字符串 字符串常量,例如: china 沒有字符串變量,用字符數(shù)組來存放字符串 字符串以 39。\039。為結(jié)束標(biāo)志 字符數(shù)組的初始化 字符串 C++語言程序設(shè)計 109 字符串的輸入 /輸出 ? 方法 逐個字符輸入輸出 將整個字符串一次輸入或輸出 例: char c[]=China。 coutc。 ? 注意 輸出字符不包括 39。\039。 輸出字符串時,輸出項是字符數(shù)組名,輸出時遇到 39。\039。結(jié)束。 輸入多個字符串時,以空格分隔;輸入單個字符串時其中 不能有空格。 例如: 程序中有下列語句: static char str1[5],str2[5],str3[5]。 cinstr1str2str3。 運行時輸入數(shù)據(jù): How are you? 內(nèi)存中變量狀態(tài)如下: str1: H o w \0 str2: a r e \0 str3: y o u ? \0 110 輸入空格時,被認為是字符串分割符 若改為: static char str[13]。 cinstr。 運行時輸入數(shù)據(jù): How are you? 內(nèi)存中變量 str 內(nèi)容如下: str: H o w \0 111 C++語言程序設(shè)計 116 字符串處理函數(shù) strcat(連接), strcpy(復(fù)制), strcmp(比較), strlen(求長度), strlwr(轉(zhuǎn)換為小寫), strupr(轉(zhuǎn)換為大寫) 頭文件 cstring C++語言程序設(shè)計 117 例 string類應(yīng)用舉例 include string include iostream using namespace std 。 void trueFalse(int x) { cout(x? True: False)endl。 } int main() { string S1=DEF, S2=123。 char CP1[ ]=ABC。 char CP2[ ]=DEF。 coutS1 is S1endl。 coutS2 is S2endl。 coutlength of S2:()endl。 coutCP1 is CP1endl。 coutCP2 is CP2endl。 coutS1=CP1 returned 。 trueFalse(S1=CP1)。 coutCP2=S1 returned 。 trueFalse(CP2=S1)。 S2+=S1。 coutS2=S2+S1:S2endl。 coutlength of S2:()endl。 } 118 C++語言程序設(shè)計 119 小結(jié)與復(fù)習(xí)建議 ? 主要內(nèi)容 數(shù)組、指針、動態(tài)存儲分配、指針與數(shù)組、指針與函數(shù)、字符串 ? 達到的目標(biāo) 理解數(shù)組、指針的概念,掌握定義和使用方法,掌握動態(tài)存儲分配技術(shù),會用數(shù)組存儲和處理字符串,會使用 String類。 ? 實驗任務(wù) 實驗六
點擊復(fù)制文檔內(nèi)容
公司管理相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1