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

正文內(nèi)容

第一章基本c程序結(jié)構(gòu)(參考版)

2024-10-02 15:28本頁面
  

【正文】 } ? 類作用域 類作用域是指類定義和相應的成員函數(shù)定義范圍 ,在該范 圍內(nèi),一個類的成員函數(shù)對同一類的數(shù)據(jù)成員具有無限 制訪問權(quán),一個類的所有成員都具有類作用域,類的所 有成員在類作用域內(nèi)發(fā)揮作用,并且可以直接使用類成 員的名字而不加所屬類的名字 class rectangle{ private: 。 thisday=d。所以調(diào)用 (2,15,1998)時, month=m。s。} 一個類中所有對象調(diào)用的成員函數(shù)都是同一代碼段,那么成員函數(shù) 又是怎么識別 month、 day、 year是屬于哪個對象的? 在對象調(diào)用 (2,15,1998)時,成員函數(shù)除了接受 3個實參外,還 接受了一個對象 s的地址。 }。 ( )。 (3,15,1997)。 Private: (2,15,1998)。 {tdate s。} int isleapyear( )。} {public: void tdate::print( ) void set(int,int,int)。 day=d。} float rectangle::perimeter( ) {return 2*(width+geight)。 } void rectangle::setheight(float newheight) {height=newheight。 }。 float area( )。 public: void setwidth(float newwidth)。 ( )。 void main( ) {tdate a。 int year。} private: int month。year=y。} 例: include class tdate {public: void set(int m,int d,int y) {month=m。 size=sz。 } {strcpy(filename,name)。 public: cout。 int type。 void main( ) int size。 } }。 class File { sz=size。sz,int amp。 2) 表示類的接口的成員函數(shù)一般定義為 public的,這樣其他對象 才能調(diào)用這些函數(shù)以發(fā)揮作用。另一些成員是公共的, 它們作為接口提供給外界使用。 將類的成員分成不同的訪問控制體現(xiàn)了面向?qū)ο蟮姆庋b和信息隱藏 的思想,類的封裝的概念首先是,數(shù)據(jù)與算法結(jié)合,構(gòu)成一個不可 分割的整體(對象)。 } float perimeter( ) {return 2*(width+height)。} void setheight(float newheight) {height=newheight。 ()。 private: (45)。 } }。 {return width*height。 public: cout( )。 float width,height。 例: class rectangle { rectangle rect。在說明的成員前面加上 public、 protected和 private 限定詞。 cout“the pemeter of rectangle is”()。 =。 rectangle rect。 } float perimeter( ) { return 2*(width+height)。 類的定義 : class 類名 { 類定義體 }; 例: class rectangle { public: float width,height。 } 類與對象 ? 類的定義 類構(gòu)成了實現(xiàn) c++面向?qū)ο蟪绦蛟O計的基礎,類是c++封裝的基本單元,它把數(shù)據(jù)和函數(shù)封裝在一起,當類的成員聲明為保護時,外部不能訪問,聲明為公共時,則在任何地方可以訪問。 date birthday。 int day。 struct student{ struct date{ int year。 =1998。} float score。 date birthday。 char name[20]。 =78。 s1=ia。 array ia。 3) 結(jié)構(gòu)變量的初始化 student jane={“jane air”,”123456”,93}。 class[1].id=“123456”。I++) cout[I]。 2) 結(jié)構(gòu)成員的訪問 結(jié)構(gòu)體名.成員名 [5] for (int I=0。 } student s1,s2。 float score。 struct array char id[7]。 ? 結(jié)構(gòu) 1) 定義 :組成結(jié)構(gòu)的各個值可以有不同的數(shù)據(jù)類型 struct student const int maxsize=100。I5。 int a[2][4]={{1,2,3},{5,6,7}}。 3) 多維數(shù)組的初始化 int a[2][4]={{1,2,3,4},{5,6,7,8}}。j++) couta[I][j]。I++) for (int j=0。 2) 多維數(shù)組的訪問 : a[i][j]的地址 : 首地址 +i*每行元素個數(shù) +j a[0][0] a[0][1] a[0][2] a[0][3] a[1][0] …… a[2][0] …… a[2][3] 遍歷二維數(shù)組用雙重循環(huán)語句 : for (int I=0。 char cal3[4]=“char”。 c) 字符數(shù)組可以用多個字符或字符串進行初始化 char cal[ ]={?c?,?h?,?a?,?r?}。 注意: a) 初始化的個數(shù) =數(shù)組元素個數(shù) int array[10]={4,5}。 str2[I]=0x0。I++) B[I]=A[I]。I++) for(int I=0。 for (int I=0。 int B[10]。 array[0] array[1] array[2] …… array[n1] 3) 數(shù)組復制 c++不支持數(shù)組變量之間的直接賦值,必須一個一個元素復制 int A[10]。I30。 注意:下標越界 int ca[10]。I++) coutarray[I]ednl。 for(int I=0。字符串的字符數(shù)組也必須是以空字符結(jié)尾 w a n g t a o \0 2) 數(shù)組元素的訪問 數(shù)組名[下標] const int n=100。 } ?頭文件 兩種形式: include 文件名 include “ 文件名 “ # include指令可以嵌套,預編譯程序會遞歸處理,將 所有的頭文件的內(nèi)容都完全展開。 b+=5。 a+=2。 } Void func( ) {static int a=2。 n+=10。 func( )。 coutabnendl。 Void main( ) {static int a。 cout“l(fā)ocal variable j=“endl。 void main( ) {int j。 delete pglobal。 pglobal=new int。 func2( )。 void func2( )。 } 注意 :內(nèi)聯(lián)函數(shù)和用 const 定義的常量都有靜態(tài)特性 ? 生存期 1) 定義 :指標識符在程序運行過程中生存的時間 靜態(tài)生存期:生命期與程序運行期相同 ,只要程序一開始運行 ,這種變量就存在 ,程序結(jié)束時 ,其生命期就結(jié)束 ,全局變量、靜態(tài)全局變量、靜態(tài)局部變量,文件作用域的變量有靜態(tài)特性 動態(tài)生存期:由程序中特定的函數(shù)調(diào)用( malloc( )和 free( ))或( new和 delete)來創(chuàng)建和釋放 局部生命期:在函數(shù)內(nèi)部聲明的變量或是塊中聲明的變量,生存期開始于聲明點,結(jié)束于其作用域結(jié)束處 例: int *pglobal。 } a=func(I)。 } void main( ) static int sfunc(int I) {int I=b。 extern int b1 static int b=3。 是沒有辦法來訪問的 同樣可以用 static來定義靜態(tài)函數(shù) ,其他文件就不能通 過說明函數(shù)原型來訪問該函數(shù) static int max(int,int)。 … } 3. 靜態(tài)全局變量與靜態(tài)函數(shù) 若不希望在一個文件中定義的某些變量或函數(shù)被其他 文件使用時,我們可以將這些變量或函數(shù)定義為靜態(tài) ( static) 例: static int I。 3) extern中說明的變量必須是全局作用域,不能是函數(shù) 的局部變量 2. 外部函數(shù) C++中函數(shù)可以共享的,即 C++中函數(shù)的說明默認是 extern的,允 許在說明這個函數(shù)原型的文件中使用這個函數(shù) 例: 文件 void print(char *) (extern 可以省略 ) void main( ) {print(“hello “)。 { … x=5。 int x。
點擊復制文檔內(nèi)容
教學課件相關推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1