(完整word版)c++整理_第1頁
(完整word版)c++整理_第2頁
免費(fèi)預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、請寫出上述程序的運(yùn)行結(jié)果:a= 60 ,ra=601.在類的成員函數(shù)中,每個(gè)成員變量之前都隱含了一個(gè)指向當(dāng)前對象的B_指針。(A)pointer( B)this(C) that(D)prt2.對定義重載函數(shù)的下列要求中,_D_是錯(cuò)誤 的。(A)要求函數(shù)參數(shù)的個(gè)數(shù)不同(B)要求函數(shù)參數(shù)中至少有一個(gè)類型不同(C)要求函數(shù)參數(shù)個(gè)數(shù)相同時(shí),參數(shù)的類型應(yīng)有所不同(D)要求函數(shù)的返回值不同先執(zhí)行_A_,再執(zhí)行_B_,后執(zhí)行_C_。(A)基類的構(gòu)造函數(shù)(B)成員對象的構(gòu)造函數(shù)(C)派生類自身的構(gòu)造函數(shù)8._A_提供了類對外部的接口;_D_只能在類的內(nèi)部作為數(shù)據(jù)被訪問;_B_不允許外界訪問,但允許派生類的對象

2、訪問。(A)公共成員函數(shù)(B)被保護(hù)成員(C)私有成員(D)私有數(shù)據(jù)成員9.類模板的使用實(shí)際上是將類模板實(shí)例化成一個(gè)具體的_A_Q(A)類(B)對象(C)函數(shù)(D)模關(guān)于虛函數(shù)的描述中,_C_是正確的。(A)虛函數(shù)是一個(gè)蠡打廠類型的成員函數(shù)(B)虛函數(shù)是一個(gè)非成員函數(shù)(C)基類中說明了虛函數(shù)后,派生類中與其對應(yīng)的 函數(shù)可省略虛函數(shù)標(biāo)志 virtual(D)派生類的虛函數(shù)與基類中相應(yīng)的虛函數(shù)應(yīng)具 有不同的參數(shù)個(gè)數(shù)和類型如果一個(gè)類至少有一個(gè)純虛函數(shù),那么就稱該類為_A_。(A)抽象類(B)虛基類(C)派生類(D)以上都不對板函數(shù)10.在類的定義體外定義成員函數(shù)時(shí), 需要在函數(shù)名 前加上_B=,而在

3、類的外部調(diào)用成員函數(shù)時(shí),需要 _c_引導(dǎo)。(A)類標(biāo)記(B)類域標(biāo)記(C 類對象(D)域運(yùn)算符11.雙目運(yùn)算符重載為成員函數(shù)時(shí)帶_A_個(gè)形式參數(shù),重載為友元函數(shù)時(shí)帶 _B_個(gè)形式參數(shù)。(A) 1( B) 2( C) 3(D) 412.在派生類中重定義基類的某成員函數(shù)后,通過派5._D_是一種特殊的成員函數(shù),其函數(shù)名同類名。它主要用來為對象分配內(nèi)存空間,對類的數(shù)據(jù)成員進(jìn)行初始化并執(zhí)行對象的其他內(nèi)部管理操作。(A)友元函數(shù)(B)析構(gòu)函數(shù)(C)拷貝構(gòu)造函數(shù)(D)構(gòu)造函數(shù)6.C+中的類有兩種用法:一種是類的實(shí)例化,即生成類的對象,并參與系統(tǒng)的運(yùn)行;另一種是通過 _C_,派生岀新的類。(A)友元函數(shù) (

4、B)多態(tài) (C)繼承 (D)構(gòu)造函數(shù)生類的對象或指針訪問到的是_,如果派生類的成員函數(shù)需要訪問基類中的重定義版本,則可以使用_C引導(dǎo)方式?;惖闹囟x版本(B)派生類的重定義版本(C)基類名域(D)派生類名域13.含有一個(gè)或以上純虛函數(shù)的類稱為_C。(A)純虛類(B)具體類(C)抽象類(D)派生類7.在定義派生類的對象構(gòu)造函數(shù)的執(zhí)行順序?yàn)?1. (5 分)#i nclude iostream.h void mai n()int a;int & ra=a;ra=7;3.4.請寫出上述程序的運(yùn)行結(jié)果:a= 60 ,ra=60a=8*ra+6;ra_=2;cout ” a= ” aa=”,a

5、 class Apublic :A(int u) : age(u), number(age+1)cout age : age , number : nu mber class NewClasspublic :NewClass( int i ); NewClass(NewClass &obj); NewClass( ) delete p; frie nd int GetValue(NewClass obj);private : int* p;NewClass: NewClass( in t i )p=new int;if ( !p ) cout Allocati on error n;

6、return ;-拷貝構(gòu)造函數(shù):NewClass:NewClass(NewClass & obj)p=new int;if(!p)cout Allocati on error n;return;*p=*obj.p;*p= i;int GetValue (NewClass obj)return *obj.p;void mai n()NewClass x(1), y(2);NewClass x1(x),y1(y);coutGetValue (x) GetValue (y)endl;coutGetValue (x1) GetValue (y1)endl;-運(yùn)行結(jié)果:J Fc+testDebu

7、gText2,exe1 21 2Press any key to continue4.( 5 分)#in clude #i nclude using n amespace std; const int SIZE=9;class Plotpublic:Plot(int i,int j)if (iSIZE)i=SIZE;if (iSIZE)j=SIZE;if (j0)j=0;x=i;y=j;frie nd ostrea m& operator (ostrea m&stream, Plot ob);private:int x,y;protected:int number; intag

8、e;void mai n()A jenn(5 分)(5 分);ostrea m& operator=0; j-)stream j;if (j= =ob.y) for ( int i=0; i2*ob.x-1; i+)stream ;stream * ;if (j= =0)break;stream e ndl;for ( int i=1; iSIZE+1; i+) stream i ;stream en dl; return stream ;void mai n ()Plot a(3, 5);char str200;ostrstream outs ( str, sizeof(str);

9、outs ae ndl;outs 0;cout Output us ing in-RAM formati ng:n;cout str;運(yùn)行結(jié)果:1 什么是虛函數(shù)?它有什么作用?(5 分)答:1.虛函數(shù)是被 virtual 關(guān)鍵字修飾的成員函數(shù)(用 virtual 聲明的函數(shù))#in clude #in clude class Newclassen dl;public:Newclass ( ) cout Con struct ingno rmally. en dl; Newclass ( char* pName )strcpy( n ame, pName );cout Con struct in

10、g with a n ame: n ame en dl;Newclass ( ) cout Destruct ing. en dl;cout Display a n ame : n ame #include using namespace std;int a5=10,20,30,40,50;vector intValue;void init()int i;for(i=0;i c1c2; coutclass Complex I _double real,image;public: Complex(double r, double i) real=r;image=i;/普通構(gòu)造函數(shù);/pos 為被

11、刪除元素在向量控制序列中的索引位置。并刪pos1, int pos2);pos1 和 pos2 分別為被交換元素在向量2 的元素。int temp;temp=intValue.at(pos1);intValue.at(pos1)=intValue.at(pos2);intValue.at(pos2)=temp;void show()int i;coutvv當(dāng)前所有元素:”;for(i=O;ivintValue.size();i+) coutvvintValue.at(i)vv ;coutvvendl;void main()init();Del(2);show();Change(0,2);sho

12、w();Complex。; /無參構(gòu)造函數(shù)friend void InputComplex(Complex &comp);friend void OutputComplex(Complex comp); friendComplex addComplex(Complex &c1, Complex &c2); / 相加;void lnputComplex(Complex &comp)cincomp.realcomp.image;Complex addComplex(Complex & c1, Complex & c2) Complex c;c.rea

13、l=c1.real+c2.real;c.image=c1.image+c2.image; return c;void OutputComplex(Complex comp)cout vv(vvcomp.realvv,vvcomp.imagevv);=void main()Complex c1,c2,result;coutvvqing shuru di yi ge fu shu de shibu hexubo vvendl;InputComplex(cl);coutvvqing shuru di er ge fu shu de shibu hexubo vvendl;InputComplex(c

14、2); result=addComplex(c1,c2);OutputComplex(cl);coutvv+;OutputComplex(c2); coutvv=;OutputComplex(result#include viostream.h#includevmath.hclass Point private:double x;double y;public: Point()Point(double x1,double y1)x=x1;y=y1;Point(Point & a);void setPoint(double x1,doubley1)x=x1;y=y1;void show(

15、);double getX()return x;double getY()return y;double Distance(Point b)returnsqrt(x-b.x)*(x-b.x)+(y-b.y)*(y-b.y);Point:Point(Point & a):x(a.x),y(a.y) voidPoint:show()cout vv ( vv x vv , vv y vv ) vv endl;class Shapevirtual double length()=0; virtual voidshow()=0;class Line:public Shapeprivate:Point sp ;Point ep ;public:Line(double x1,double y1, double x2,doubley2 ):sp(Point(x1,y1),ep(Point (x2,y2) Line(constPoint & p, float x, f

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論