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

正文內容

第六章數(shù)組指針與字符串(參考版)

2025-07-23 23:57本頁面
  

【正文】 } 118 C++語言程序設計 119 小結與復習建議 ? 主要內容 數(shù)組、指針、動態(tài)存儲分配、指針與數(shù)組、指針與函數(shù)、字符串 ? 達到的目標 理解數(shù)組、指針的概念,掌握定義和使用方法,掌握動態(tài)存儲分配技術,會用數(shù)組存儲和處理字符串,會使用 String類。 coutS2=S2+S1:S2endl。 trueFalse(CP2=S1)。 trueFalse(S1=CP1)。 coutCP2 is CP2endl。 coutlength of S2:()endl。 coutS1 is S1endl。 char CP1[ ]=ABC。 void trueFalse(int x) { cout(x? True: False)endl。 cinstr。 cinstr1str2str3。 輸入多個字符串時,以空格分隔;輸入單個字符串時其中 不能有空格。\039。\039。 coutc。\039。 static char str[]=program。}。,39。,39。,39。,39。,39。,39。,39。 //字符 ACSII值 static char str[8]={39。 i++) points[i].Move( (i).GetX(), (i).GetY())。 for (int i=0。 pointsArray) { numberOfPoints =。 //其他成員同例 618 }。 class ArrayOfPoints { public: ArrayOfPoints(ArrayOfPointsamp。 100 拷貝前 拷貝后 pointsArray1的數(shù)組元素占用的內存 points numberOfPoints pointsArray1 points numberOfPoints pointsArray1 pointsArray1的數(shù)組元素占用的內存 points numberOfPoints pointsArray2 101 C++語言程序設計 102 例 621對象的深拷貝 include iostream using namespace std。 coutPoint_1 of array2: (1).GetX() , (1).GetY()endl。 coutAfter the moving of pointsArray1:endl。 98 (0).Move(25,30)。 coutPoint_0 of array2: (0).GetX() , (0).GetY()endl。 ArrayOfPoints pointsArray2(pointsArray1)。 (0).Move(5,10)。 cinnumber。 class ArrayOfPoints { //類的聲明同例 618 //?? }。 淺拷貝與深拷貝 C++語言程序設計 97 例 620對象的淺拷貝 include iostream using namespace std。 返回值:無 頭文件: cstdlib 和 cmalloc C++語言程序設計 96 淺拷貝與深拷貝 ? 淺拷貝 實現(xiàn)對象間數(shù)據(jù)元素的一一對應復制。 頭文件: cstdlib 和 cmalloc C++語言程序設計 95 動態(tài)內存釋放函數(shù) ? void free( void *memblock )。 參數(shù) size:欲分配的字節(jié)數(shù) 返回值:成功,則返回 void型指針。 } coutendl。 k++) //將指針 cp作為數(shù)組名使用, //通過數(shù)組名和下標訪問數(shù)組元素 coutcp[i][j][k] 。 j++) { for (k=0。 i++) { for (j=0。 //通過指針訪問數(shù)組元素 for (i=0。 k9。 j9。 i8。 cp = new float[8][9][8]。 int main() { float (*cp)[9][8]。 char (*fp)[3]。例如: char (*fp)[3]。 //通過指針訪問數(shù)組元素的成員 (1).Move(15,20)。 ArrayOfPoints points(number)。 coutPlease enter the number of points:。 }。 } private: Point *points。 } Pointamp。 numberOfPoints=0。 points=new Point[n]。 class Point { //類的聲明同例 616 ? }。 //刪除整個對象數(shù)組 return 0。 //通過指針訪問數(shù)組元素的成員 coutDeleting...endl。 //創(chuàng)建對象數(shù)組 Ptr[0].Move(5,10)。 class Point { //類的聲明同例 616,略 }。 return 0。 Ptr1=new Point(1,2)。 delete Ptr1。 int main() { coutStep One:endl。 } private: int X,Y。} void Move(int x,int y) { X=x。 } int GetX(){return X。 cout Constructor called.\n。} Point(int xx,int yy) { X=xx。 class Point {public: Point() { X=Y=0。 P必須是new操作的返回值。 結果值: 成功: T類型的指針,指向新分配的內存。//輸出對象序號,通過指針訪問靜態(tài)函數(shù)成員 //()。//聲明對象 B coutPoint B,(),()。//輸出對象序號,通過指針訪問靜態(tài)函數(shù)成員 //()。 //聲明對象 A coutPoint A,(),()。 //靜態(tài)數(shù)據(jù)成員定義性說明 int main() //主函數(shù) { //指向函數(shù)的指針,指向類的靜態(tài)成員函數(shù) void (*gc)()=Point::GetC。 //靜態(tài)數(shù)據(jù)成員引用性說明 }。 } private: //私有數(shù)據(jù)成員 int X,Y。 //B.(*count) } 78 C++語言程序設計 79 例 615通過指針訪問類的靜態(tài)函數(shù)成員 include iostream using namespace std。 //聲明對象 B coutPoint B,() ,()。 //直接通過指針訪問靜態(tài)數(shù)據(jù)成員 cout Object id=*countendl。 Point A(4,5)。 //int point::*count==amp。 //靜態(tài)數(shù)據(jù)成員定義性說明 int main() //主函數(shù) { //聲明一個 int型指針,指向類的靜態(tài)成員 int *count=amp。 countP++。p) { X=。 }。 //靜態(tài)數(shù)據(jù)成員引用性說明 // int countP。} int GetY() {return Y。p)。countP++。 class Point //Point類聲明 {public: //外部接口 Point(int xx=0, int yy=0) {X=xx。 //( 4) coutp1*p_Gext ()endl。 //( 2)使用對象指針訪問成員函數(shù) cout(p1GetX)()endl。 //聲明對象指針并初始化 //聲明成員函數(shù)指針并初始化 int (Point::*p_GetX)()=Point::GetX。 //聲明對象 A Point *p1=amp。A。point::countp。 C++語言程序設計 73 指向類的非靜態(tài)成員的指針 ? 指向數(shù)據(jù)成員的指針 說明指針應該指向哪個成員 指針名 =amp。 聲明指向公有數(shù)據(jù)成員的指針 類型說明符 類名 ::*指針名; Int point::*pc。 ? private int x,int y。 thisY=yy。 } Point p1(1,2),p2(3,4)。 C++語言程序設計 71 this指針 例如: Point類的構造函數(shù)體中的語句: Point(int xx,int yy) {thisX=xx。 ? 明確地指出了成員函數(shù)當前所操作的數(shù)據(jù)所屬的對象。 }。 }。 C++語言程序設計 69 正確的程序 class Fred。 class Fred { Barney y。 //前向引用聲明 class Barney { Fred x。 return 0。 x=ptrGetX()。A。 Point *ptr。 Printf(“%d” ,)//(*ps).age ps age ? 通過指針訪問對象成員 (公有 ) ? 對象指針名 成員名 ptrgetx() 相當于 (*ptr).getx()。 ps=amp。 pi=amp。 ptr=amp。 int *pi。 struct stdent s。 } 64 運行結果: This is the print stuff function. This is the print stuff function. The data to be listed is The data to be listed is The data to be printed is The data to be printed is 65 C++語言程序設計 66 對象指針的一般概念 ? 聲明形式 類名 *對象指針名; ? 例 Point A(5,10)。 } void print_message(float list_this_data) { coutThe data to be listed is list_this_dataendl。 print_float(pi)。 function_pointer = print_float。 function_pointer(two_pi)。 function_pointer(pi)。 print_stuff(pi)。 int main() { float pi=(float)。 void print_float(float data_to_p
點擊復制文檔內容
公司管理相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1