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

正文內(nèi)容

c程序設(shè)計(jì)第七章類(lèi)模板與向量-資料下載頁(yè)

2025-01-06 10:52本頁(yè)面
  

【正文】 9。M39。,40)。 per[2].set(王五 ,39。M39。,35)。 for(int i=0。i3。i++) per[i].show()。 } 54 訪(fǎng)問(wèn)向量容量信息的方法 size(), max_size(), capacity(), empty() 用于得到當(dāng)前向量的大小信息 四、向量最基本的操作方法 向量有許多成員函數(shù)提供不同的操作。 1) size(): 返回當(dāng)前向量中已經(jīng)存放的對(duì)象的個(gè)數(shù)。 2) max_size(): 返回向量可以容納的最多對(duì)象的個(gè)數(shù)。 3) capacity(): 返回?zé)o需再次分配內(nèi)存就能容納的對(duì)象的個(gè)數(shù)。當(dāng)存放空間已滿(mǎn),又增加一個(gè)元素時(shí),它在原來(lái)的基礎(chǔ)上自動(dòng)翻倍擴(kuò)充空間,以便存放更多的元素。 4) empty(): 測(cè)試向量是否為空,為空時(shí)返回 true。 55 例題 () include iostream include vector using namespace std。 void main() { coutsize:\tmax_size\tcapa\tempty:endl。 vectorcharv0。 cout()\t()\t“ ()\t()endl。 vectorintv1(5)。 cout()\t()\t“ ()\t()endl。 vectorintv2(3,5)。 cout()\t()\t“ ()\t()endl。 v2=v1。 cout()\t()\t“ ()\t()endl。 } 56 訪(fǎng)問(wèn)向量中對(duì)象的方法 1) front():返回向量中的第一個(gè)元素 2) back():返回向量中的最后一個(gè)元素 3) operator[](n):返回向量中下標(biāo)為 n的元素 57 例題:分析以下程序的運(yùn)行結(jié)果 () include iostream include vector using namespace std。 void main() { char s[]=abcdef。 vectorcharvs(s,s+strlen(s))。 coutfirst is:() endl。 coutlast is:() endl。 for(int i=0。i()。i++) cout [](i)。 coutendl。 } 58 在向量中插入對(duì)象的方法 1) push_back(const Tamp。):在 尾部 插入一個(gè)元素 2) insert(iterator it,const Tamp。): 在 it所指的向量 位置前 插入一個(gè)元素 3) insert(iterator it,size_type n,const Tamp。X): 在 it所指的向量 位置前 插入 n個(gè)值為 X的元素 59 例題 () class person {string name。 char sex。 int age。 public: person( ……) { ……} void set( ……) {……} void show() {cout姓名 :name\t性別 : sex\t年齡 ageendl。}}。 void main() {person per[3]={person(張三 ,39。F39。,30), person(李四 ,39。M39。,40),person(王五 ,39。M39。,35)}。 vectorpersonv(per,per+3)。 cout共有 () 個(gè)人 endl。 cout可以存放 () 個(gè)人 endl。 for(int i=0。i()。i++) v[i].show()。 } [] (i).show()。 60 …… void main() {…… coutthe last one is:。 ().show()。 cout“新加一人!” endl。 //尾部追加 1人 (person(趙六 ,39。M39。,18))。 cout共有 () 個(gè)人 endl。 cout可以存放 () 個(gè)人 endl。 coutthe last one is:。 ().show()。 } 61 void main() {…… cout“新插入 2人!” endl。 //新插入 2人 (()+2,2,person(趙六 ,39。M39。,18))。 cout共有 ()個(gè)人 endl。 cout可以存放 ()個(gè)人 endl。 for(i=0。i()。i++) [] (i).show()。 coutthe last one is:。 ().show()。 } 62 從向量中刪除對(duì)象的方法 1) pop_back():刪除最后一個(gè)元素 2) erase( iterator it):刪除 it所指的元素 4) clear():刪除所有元素。 empty()返回為 1. 63 例題 :刪除向量元素操作 ——pop_back() include iostream include vector include algorithm include functional using namespace std。 void main() { int a[]={0,1,2,3,4,5,6,7,8}。 vectorintv(a,a+9)。 cout共有 ()個(gè)數(shù) ,可以存放 ()個(gè)數(shù) endl。 copy((),(),ostream_iteratorint(cout, ))。 cout最后一個(gè)數(shù)是 :*(()1)endl。 cout刪除最后一個(gè)數(shù) endl。 ()。 cout共有 ()個(gè)數(shù) ,可以存放 ()個(gè)數(shù) endl。 copy((),(),ostream_iteratorint(cout, ))。 cout最后一個(gè)數(shù)是 :*(()1)endl。 } 64 //刪除向量元素 ——erase include iostream include vector include algorithm include functional using namespace std。 void main() { int a[]={0,1,2,3,4,5,6,7,8}。 vectorintv(a,a+9)。 cout共有 ()個(gè)數(shù) ,可以存放 ()個(gè)數(shù) endl。 copy((),(),ostream_iteratorint(cout, ))。 coutendl請(qǐng)輸入要?jiǎng)h除的數(shù) :endl。 int n。 cinn。 (find((),(),n))。 cout共有 ()個(gè)數(shù) ,可以存放 ()個(gè)數(shù) endl。 copy((),(),ostream_iteratorint(cout, ))。 } 65 //刪除向量元素 ——clear include iostream include vector include algorithm include functional using namespace std。 void main() { int a[]={0,1,2,3,4,5,6,7,8}。 vectorintv(a,a+9)。 cout共有 ()個(gè)數(shù) ,可以存放 ()個(gè)數(shù) endl。 copy((),(),ostream_iteratorint(cout, ))。 coutendl清空向量! endl。 ()。 cout共有 ()個(gè)數(shù) ,可以存放 ()個(gè)數(shù) endl。 cout()endl。 } 66 a b c d e f g h h i j 67 68 69 70 71 C++中,利用向量類(lèi)模板定義一個(gè)具有 20個(gè) int的向量,其所有元素被置為 1,實(shí)現(xiàn)此操作的語(yǔ)句是 ______。 是 ______。 C++中,利用向量類(lèi)模板定義一個(gè)具有 20個(gè) double的向量,其元素均被置為,實(shí)現(xiàn)此操作的語(yǔ)句是 _______。 _________。
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)課件相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1