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

正文內(nèi)容

第一章基本c程序結(jié)構(gòu)-資料下載頁(yè)

2024-09-28 15:28本頁(yè)面

【導(dǎo)讀】基本數(shù)據(jù)類型的修飾符號(hào)。數(shù)據(jù)在計(jì)算機(jī)中的存儲(chǔ)。輸出時(shí)有無(wú)區(qū)別?cout<<“mynameis”<<end1<<“jone”;2)輸出換行字符‘\n?

  

【正文】 student jane={“jane air”,”123456”,93}。 student class[5]={{“janeair”,”123456”,93},{“zhang”, ”3333”,83}} 4) 結(jié)構(gòu)的賦值 student s1,s2。 array ia。 屬于同一結(jié)構(gòu)類型的各個(gè)變量之間可以相互賦值 s1=s2。 s1=ia。 對(duì)各個(gè)成員可以賦值 =“12345”。 =78。 ? 結(jié)構(gòu)嵌套 struct date{ struct student{ int year。 char name[20]。 int month。 date birthday。 int day。} float score。 } student john。 =1998。 =30。 struct student{ struct date{ int year。 int month。 int day。} char name[20]。 date birthday。 float score。 } 類與對(duì)象 ? 類的定義 類構(gòu)成了實(shí)現(xiàn) c++面向?qū)ο蟪绦蛟O(shè)計(jì)的基礎(chǔ),類是c++封裝的基本單元,它把數(shù)據(jù)和函數(shù)封裝在一起,當(dāng)類的成員聲明為保護(hù)時(shí),外部不能訪問(wèn),聲明為公共時(shí),則在任何地方可以訪問(wèn)。學(xué)習(xí)本章后,要求掌握聲明和定義類和成員函數(shù)的方法,掌握訪問(wèn)成員函數(shù)的方法,理解保護(hù)數(shù)據(jù)如何屏蔽外部訪問(wèn)的原理,使得對(duì)類的封裝有更好的認(rèn)識(shí)。 類的定義 : class 類名 { 類定義體 }; 例: class rectangle { public: float width,height。 float area( ) {return width*height。 } float perimeter( ) { return 2*(width+height)。 } }。 rectangle rect。 可以使用它的成員: =45。 =。 cout“the area of rectangle is”( )endl。 cout“the pemeter of rectangle is”()。 ? 成員的訪問(wèn)控制 C++在定義類時(shí) ,可以將類的各個(gè)成員劃分成不同的訪問(wèn) 級(jí)別。在說(shuō)明的成員前面加上 public、 protected和 private 限定詞。 Public表示成員是公開(kāi)的,可以通過(guò)圓點(diǎn)操作符 ‘ .? 來(lái)訪問(wèn), protected和 private表示私有,不能通過(guò)圓點(diǎn)操 作符來(lái)訪問(wèn)。 例: class rectangle { rectangle rect。 private: =45。 float width,height。 =。 public: cout( )。 float area( ) cout( )。 {return width*height。 } float perimeter( ) {return 2*(width+height)。 } }。 增加了對(duì)私有成員操作的函數(shù)后的 rectangle類 class rectangle { rectangle rect。 private: (45)。 float width,height。 ()。 public: void setwidth(float newwidth) {width=newwidth。} void setheight(float newheight) {height=newheight。} float area( ) {return width*height。 } float perimeter( ) {return 2*(width+height)。 } }。 將類的成員分成不同的訪問(wèn)控制體現(xiàn)了面向?qū)ο蟮姆庋b和信息隱藏 的思想,類的封裝的概念首先是,數(shù)據(jù)與算法結(jié)合,構(gòu)成一個(gè)不可 分割的整體(對(duì)象)。其次是,這個(gè)整體中一些成員是保護(hù)的,它 們被有效地屏蔽,以防外界的干擾和誤操作。另一些成員是公共的, 它們作為接口提供給外界使用。 類的成員是定義成私有還是定義成公有,可以按以下方法來(lái)確定: 1) 類的數(shù)據(jù)成員一般不公開(kāi),類的函數(shù)成員才是類的對(duì)外接口。 2) 表示類的接口的成員函數(shù)一般定義為 public的,這樣其他對(duì)象 才能調(diào)用這些函數(shù)以發(fā)揮作用。 3) 表示類的實(shí)現(xiàn)的成員函數(shù)定義為 protected或 private 自測(cè)題 include void get(char *name,int amp。sz,int amp。tp) include { strcpy(name,filename)。 class File { sz=size。 private: tp=type。 } }。 char filename[64]。 void main( ) int size。 {File file。 int type。 (“myfile”,1000,1)。 public: cout。 void set(char *name,int sz,int tp) cout 。 } {strcpy(filename,name)。 cout 。 size=sz。 type=tp。} 例: include class tdate {public: void set(int m,int d,int y) {month=m。day=d。year=y。} void print( ) {coutmonth“/”day“/”yearendl。} private: int month。 int day。 int year。}。 void main( ) {tdate a。 (2,4,1998)。 ( )。 } ? 類的成員函數(shù) 對(duì)于大的成員函數(shù)來(lái)說(shuō),直接把代碼放在類定義中使用 起來(lái)十分不便,類的函數(shù)成員的定義體可以定義在類定 義體的里面,也可以定義在類定義體的外面 例: class rectangle { private: float width,height。 public: void setwidth(float newwidth)。 void setheight(float newheight)。 float area( )。 float perimeter( )。 }。 void rectangle::setwidth(float newwidth) {width=newwidth。 } void rectangle::setheight(float newheight) {height=newheight。} float tectangle::area( ) {return width*height。} float rectangle::perimeter( ) {return 2*(width+geight)。 } 成員函數(shù)必須用對(duì)象來(lái)調(diào)用 include void tdate::set(int m,int d,int y) Class tdate {month=m。 day=d。year=y。} {public: void tdate::print( ) void set(int,int,int)。 {coutmonth“/”day“/”year。} int isleapyear( )。 void main( ) Void print( )。 {tdate s。 tdate t。 Private: (2,15,1998)。 int month。 (3,15,1997)。 int day。 ( )。 int year。 }。 ( )。} 一個(gè)類中所有對(duì)象調(diào)用的成員函數(shù)都是同一代碼段,那么成員函數(shù) 又是怎么識(shí)別 month、 day、 year是屬于哪個(gè)對(duì)象的? 在對(duì)象調(diào)用 (2,15,1998)時(shí),成員函數(shù)除了接受 3個(gè)實(shí)參外,還 接受了一個(gè)對(duì)象 s的地址。這個(gè)地址被一個(gè)隱含的形參 this指針?biāo)@ 得等同于執(zhí)行 this=amp。s。所有對(duì)數(shù)據(jù)成員的訪問(wèn)都隱含地被加上前綴 This。所以調(diào)用 (2,15,1998)時(shí), month=m。 等價(jià)于 thismonth=m ;等價(jià)于 =m; set( )成員函數(shù)還可表示成下列代碼: void tdate::set(tdate *this,int m,int d,int y) {thismonth=m。 thisday=d。 thisyear=y。 } ? 類作用域 類作用域是指類定義和相應(yīng)的成員函數(shù)定義范圍 ,在該范 圍內(nèi),一個(gè)類的成員函數(shù)對(duì)同一類的數(shù)據(jù)成員具有無(wú)限 制訪問(wèn)權(quán),一個(gè)類的所有成員都具有類作用域,類的所 有成員在類作用域內(nèi)發(fā)揮作用,并且可以直接使用類成 員的名字而不加所屬類的名字 class rectangle{ private:
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1