




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、02328面向?qū)ο蟪绦蛟O(shè)計面向?qū)ο蟪绦虻幕驹厥?對象表達(dá)式 long(int var) 也可表示為 (long)int var要讓一個類中的所有對象具有共同的數(shù)據(jù),應(yīng)使用 靜態(tài)數(shù)據(jù)成員在C+中,頭文件擴(kuò)展名是 h下列數(shù)據(jù)類型中不屬于C+語言的基本數(shù)據(jù)類型是 枚舉類型設(shè)已有函數(shù)int min(int,int),該min函數(shù)功能為返回兩個參數(shù)中的較小值,若求22,59,70三者中最小值,下列表達(dá)式不正確的是 int m=min(22,59,70)對于下面的函數(shù)原型聲明:void testDefautParam(int a, int b=7, char z='*'); 下列函數(shù)調(diào)
2、用中,不合法的是 testDefautParam(5,'#');已有函數(shù)double Fun1(int,int);下列函數(shù)中不可以定義為Fun1函數(shù)的重載函數(shù)的是 int Fun1(int,int)有關(guān)析構(gòu)函數(shù)的說法,不正確的是 析構(gòu)函數(shù)和構(gòu)造函數(shù)一樣可以有形參類定義的內(nèi)容允許被其對象無限制地訪問的是 public 部分C+語言可用p.a的形式訪問派生類對象p的基類成員a,其中a是 公有繼承的公有成員對于友元函數(shù),下列描述中正確的 友元不是本類的成員函數(shù)關(guān)于成員函數(shù)的重載,說法正確的是 函數(shù)重載,要求函數(shù)名相同,但參數(shù)個數(shù)不同或參數(shù)個數(shù)相同但其類型不同能實(shí)現(xiàn)對對象進(jìn)行初始化功能
3、的是 構(gòu)造函數(shù)多繼承派生類構(gòu)造函數(shù)構(gòu)造對象時,被最先調(diào)用的是 虛基類的構(gòu)造函數(shù)面向?qū)ο蟪绦蛟O(shè)計有以下主要特點(diǎn),即抽象、封裝、繼承和 多態(tài)假設(shè)int a=l ,b=2;則表達(dá)式(+a/b) * b-的值為 2 無論是什么繼承方式,派生類的成員不能訪問基類 私有 屬性的成員。靜態(tài)成員屬于 類 ,非靜態(tài)成員屬于對象。用于輸出表達(dá)式值的標(biāo)準(zhǔn)輸出流對象是 cout在函數(shù)模板的參數(shù)中,用class修飾的參數(shù)稱為 模板 參數(shù)。函數(shù)重載時,編譯系統(tǒng)會根據(jù)形參的個數(shù)或 形參的類型 來區(qū)分。編譯時的多態(tài)性可以通過使用 重載 來實(shí)現(xiàn)。設(shè)要把一個文件輸出流對象thisFile與文件“d:myfilecode.txt”
4、相關(guān)聯(lián),所用的C+語句是 thisFile.open(“d:myfilecode.txt”) 。C+中,已知char *p1=new char(10); 則釋放p1指向的內(nèi)存使用語句是 delete p1 。下列程序?qū)崿F(xiàn)將用戶輸入的字符串逆向輸出。例如:輸入的字符串為ABCDE,則輸出為EDCBA。#include <iostream>using namespace std;void main( )char str180; cin>>str; int k=strlen(str);for (int i=0; i<k; i+)
5、cout<<strk-i-1; 下列程序?qū)崿F(xiàn)了對復(fù)數(shù)進(jìn)行加法運(yùn)算,請將程序補(bǔ)充完整。#include<iostream>#include<fstream>using namespace std;Class complex /定義一個復(fù)數(shù)類 public: int real; int imag; complex(int r=0,int i=0) real=r;imag=i;complex operator+( complex &a ,complex& b) int r=a.real+b.real; int i=a.imag+b.imag; re
6、turn complex(r,i) ;void main( ) complex x(1,2),y(3,4),z; z=x+y;cout<<z.real<<“+”<<z.imag<<“I”<<endl;下面函數(shù)模板求,其中n為整數(shù)。#include <iostream>using namespace std; template <class T>; double power(T x, int n)if(x=0) return 0;if(n=0) return 1;T powerx=1;for (int i=0;
7、i<abs(n); i+)powerx=powerx*x;if (n<0)return 1.0/powerx;else return powerx; 在下面橫線處填上適當(dāng)內(nèi)容,完成類B的定義。#include <iostream>using namespace std;class A public:A( ) a=0;A(int i) a=i;void print( ) cout<<a<<”,”; private: int a;class B:public A public:B( int i ) b1=b2=0;B(int i, int j, in
8、t k): A(i) b1=j; b2=k; /使a的值為ivoid print( )A:print( ); cout<<b1<<”,”<<b2<<endl;private: int b1, b2;完成下面類中的成員函數(shù)的定義。class triangleprivate:int base,height;/三角形的底和高public:triangle(int base,int height);triangle(triangle &t);triangle:triangle(int a,int b)base=a; height =b;trian
9、gle:triangle( triangle &t )base =t. base;height =t. height;以下程序是定義一個累加器類sumA,對其重載運(yùn)算符“+”,請?zhí)羁?。class sumA private: int n;public:sumA() n=0;sumA(int i) n=i; sumA operator + (sumA a) /運(yùn)算符重載函數(shù)sumA t; t.n=n+a.n; return t; /函數(shù)返回void disp() cout<<"n="<<n<<endl;void main()sumA
10、k1(7),k2(27),k3;k3=k1+k2;k1.disp(); k2.disp(); k3.disp(); 寫出下列程序的運(yùn)行結(jié)果:#include <iostream>using namespace std;void swap(int x, int y)int t;t=x; x=y; y=t;void main( )int a=80, b=100;cout<<”a=”<<a<<”,b=”<<b<<endl;swap(a,b);cout<<”a=”<<a<<”,b=”<&l
11、t;b<<endl;答:結(jié)果是:a=80,b=100a=80,b=100寫出下列程序的運(yùn)行結(jié)果:#include <iostream>using namespace std;class BASE public:BASE( ) cout<<”BASE”;class DERIVED : public BASE public: DERIVED ( ) cout<<” DERIVED”;void main( )DERIVED obj;答:結(jié)果是:DERIVEDBASE寫出下列程序的運(yùn)行結(jié)果:#include <iostream>using n
12、amespace std;class A public:A( ) cout<<”A”; A( ) cout<<”-A”; ;class B : public AA* p; public:B( ) cout<<”B”; p=new A( ); B( ) cout<<”-B”; delete p; ;void main( )B obj;答:結(jié)果是:ABA-B-A-A編寫一個函數(shù)int StrNum(char *s, char *subs),其功能是:統(tǒng)計子字符串subs在字符串s中出現(xiàn)的次數(shù)。答:#include <iostream>us
13、ing namespace std;int StrNum(char *s, char *subs) int n=0;int h1,h2;int p1,p2;h1=strlen(s);h2=strlen(subs);p1=0;while (p1<h1) p2=0;while (sp1=subsp2&&p2<h2&&p1<h1) p1+; p2+;if (p1=h1 && p2<h2) break; if (p2=h2) n+;elsep1=p1-p2+1; return n定義一個Point類,派生出圓Circle類,并增加
14、一函數(shù)Area()計算圓的面積。不要求定義測試類。#include <iostream>using namespace std;class Point public:Point(float ax , float ay)x=ax; y=ay; private:float x;float y;class Circle : public Point public:Circle(float ax, float ay, float ar); float Area( ) return 3.14*r*r; private:float r;Circle:Circle(float ax, float
15、 ay, float ar) : Point(ax, ay) r=ar; 下列不屬于面向?qū)ο蟪绦蛟O(shè)計的特征的是 完整性已知:int m=10; 下列表示引用的方法中正確的是 int &x=m;如果要對AB類中的整型靜態(tài)變量c賦初值0,則書寫語句正確的是 static int AB:c=0;設(shè)有數(shù)組定義:char array=”China”; 則數(shù)組array所占的空間是 6個字節(jié)可用來替換宏替換“#define E 2.718281828”的語句是 Const Float E 2.718281828;假定要對類AB定義加號操作符重載成員函數(shù),實(shí)現(xiàn)兩個AB類對象的加法,并返回相加結(jié)果,則
16、該成員函數(shù)的聲明語句為 AB operator+(AB &a)設(shè)類ClassA中存在類成員static double x,則下列初始化方式正確的是 double ClassA:x=25在繼承中,派生類擁有的基類個數(shù)為 至少1個運(yùn)用運(yùn)算符delete刪除一個動態(tài)對象時 系統(tǒng)首先為該動態(tài)對象調(diào)用析構(gòu)函數(shù),再釋放其占用的內(nèi)存基類中的protected成員可以通過public派生,其在派生類中的可見性為 protected派生類的對象可以訪問的基類成員是 公有繼承的基類的公有成員關(guān)于友元函數(shù)的說法正確的是 使用友元函數(shù)的主要目的是提高程序執(zhí)行效率,因為可直接調(diào)用該類私有變量一個類擁有多個構(gòu)造函
17、數(shù),則這些構(gòu)造函數(shù)間為 重載關(guān)系下列關(guān)于類的權(quán)限的描述,說法錯誤的是 類本身的成員函數(shù)只能訪問自身的私有成員使用delete刪除對象數(shù)組時,描述正確的是 數(shù)組中各元素都調(diào)用析構(gòu)函數(shù)假設(shè)int a=2,b=3;則表達(dá)式(+a/b) * b-的值為 3 。面向?qū)ο蟪绦蛟O(shè)計有以下主要特點(diǎn),即抽象、 封裝 、繼承和多態(tài)。運(yùn)行時的多態(tài)性主要是通過 虛函數(shù) 來實(shí)現(xiàn)。在用class定義一個類時,數(shù)據(jù)成員和成員函數(shù)的默認(rèn)訪問權(quán)限是私有 。用于從鍵盤上為變量輸入值的標(biāo)準(zhǔn)輸入流對象是 cin 定義一個函數(shù)模板要用到的第一個修飾符是 template C+中,已知char *p1=new cha
18、r10; 則釋放p1指向的內(nèi)存使用語句是 delete p1 。靜態(tài) 成員函數(shù)中不能直接引用類中說明的非靜態(tài)成員。設(shè)要把一個文件輸出流對象thisFile與文件“d:myfilecode.txt”相關(guān)聯(lián),所用的C+語句是 thisFile.open(“d:myfilecode.txt”) 。函數(shù)重載時,編譯系統(tǒng)會根據(jù)形參的類型或 形參的個數(shù) 來區(qū)分。下列程序的功能是:將字符數(shù)組s2中的全部字符(含0)復(fù)制到字符數(shù)組s1中,不用strcpy函數(shù)。#include <iostream>using namespace std;void main( )char s11
19、80, s2180;cin>>s2;for (int i=0; s2i!=/0 ; i+)/非0字符的復(fù)制s1i=s2i; s1i=s2i; cout<<s1;下列程序的功能是求兩個浮點(diǎn)數(shù)之差,在下面橫線處填上cha函數(shù)的原型聲明、調(diào)用方法。#include <iostream>using namespace std;void main( )float a,b; float cha(float,float) a=12.5;b=6.5;float c = cha(a,b) ; cout<<c<<endl;float cha(float
20、x,float y)float w;w=x-y;return w;在程序下劃線處填上缺少的程序部分,源程序如下:#include <iostream>using namespace std;template < class T >T fun(T x) T y; y=x*x-T(5); return y;void main() float a=2; cout<<fun(a);在下面橫線處填上適當(dāng)內(nèi)容,完成類中成員函數(shù)的定義。class A int *a;int n;public:A(int nn=0):n(nn)if(n=0) a=0;elsea=new in
21、tn; A( )delete a; /定義析構(gòu)函數(shù),釋放動態(tài)數(shù)組空間;以下程序是定義一個累加器類sumA,對其重載運(yùn)算符“+”,請?zhí)羁?。class sumA private: int n;public:sumA() n=0;sumA(int i) n=i; sumA operator + (sumA a) /運(yùn)算符重載函數(shù)sumA t; t.n=n+a.n; return t; /函數(shù)返回void disp() cout<<"n="<<n<<endl;void main()sumA k1(7),k2(27),k3;k3=k1+k2;k1.
22、disp(); k2.disp(); k3.disp(); 寫出下列程序的運(yùn)行結(jié)果:#include <iostream>using namespace std;class FunArrayint *pa; / 指向一個數(shù)組空間int size; /數(shù)組元素個數(shù) public:FunArry(int a, int thesize):pa(a), size(thesize) int Size( ) return size; int& operator (int index) return paindex-1; ;void main( )int s=1,3,5,7,9;FunA
23、rray ma(s, sizeof(s)/sizeof(int);ma3=11;for (int i=1; i<=ma.Size( ); i+) cout<<mai<<,;答:1,3,11,7,9,寫出下列程序的運(yùn)行結(jié)果:#include <iostream>using namespace std;class A public:A( ) cout<<”A”; ;class B public:B( ) cout<<”B”; ;class C : public AB b; public:C( ) cout<<”C”; ;
24、void main( )C obj;答:ABC寫出下列程序的運(yùn)行結(jié)果:#include <iostream>using namespace std;class MyClass public:int number;void set(int i);int number=3;void MyClass:set (int i)number=i;void main( )MyClass my1;int number=10;my1.set(5);cout<<my1.number<<endl;my1.set(number);cout<<my1.number<
25、<endl;my1.set(:number);cout<<my1.number<<endl;答:5103編程實(shí)現(xiàn):輸入一個 n*n 的矩陣,求出兩條對角線元素值之和。答:#include <iostream>using namespace std;int main( )int n =0; int *array; int sum = 0; cout<<"input num:"<<endl; cin>>n; array = new int*n; for(int k =0; k<n; k+) ar
26、rayk = new intn; for(int i = 0; i<n;i+) for(int j = 0; j<n;j+) cin>>arrayij; for(i = 0; i<n; i+) sum+=arrayii+ arrayin-i-1; cout<<sum<<endl;return 0; 定義一個Point類,派生出矩形Rectangle類,并增加一函數(shù)Area()計算矩形的面積。不要求定義測試類。答: #include <iostream>using namespace std;class Point public:
27、Point(float ax , float ay)x=ax; y=ay; private:float x;float y;class Rectangle : public Point public:Rectangle (float ax, float ay, float w, float h); float Area( ) return width*high; private:float width;float high;Rectangle: Rectangle (float ax, float ay, float w, float h) : Point(ax, ay) width=w;hi
28、gh=h; 在C+中,函數(shù)原型不能標(biāo)識 函數(shù)的功能在C+程序中,對象之間的相互通信通過 調(diào)用成員函數(shù)實(shí)現(xiàn)對于任意一個類,析構(gòu)函數(shù)的個數(shù)最多為 1假定一個二維數(shù)組的定義語句為“int a34=3,4,2,8,6;”,則元素a12的值為 6 友元關(guān)系不能 繼承 對重載函數(shù)形參的描述中,錯誤的是 參數(shù)的個數(shù)、類型、順序都相同,只是函數(shù)的返回值類型不同下面說法正確的是 內(nèi)聯(lián)函數(shù)在編譯時是將該函數(shù)的目標(biāo)代碼插入每個調(diào)用該函數(shù)的地方可以用p.a的形式訪問派生類對象p的基類成員a,其中a是 公有繼承的公有成員在公有派生情況下,有關(guān)派生類對象和基類對象的關(guān)系,不正確的敘述是 派生類的對象可以賦給基類的對象在每
29、個C+程序中都必須包含有這樣一個函數(shù),該函數(shù)的函數(shù)名為 main 設(shè)x和y均為bool量,則x&&y為真的條件是 它們均為真下面的哪個保留字不能作為函數(shù)的返回類型 new 假定a為一個整型數(shù)組名,則元素a4的字節(jié)地址為 a+16 假定AB為一個類,則執(zhí)行“AB a(4) , b3 , * p2 ”語句時,自動調(diào)用該類構(gòu)造函數(shù)的次數(shù)為 4 假定要對類AB定義加號操作符重載成員函數(shù),實(shí)現(xiàn)兩
30、個AB類對象的加法,并返回相加結(jié)果,則該成員函數(shù)的聲明語句為 AB operator+(AB & a) 循環(huán)語句whlie(int i=0 )i-;的循環(huán)次數(shù)是 0 如果有int x,*p; float y,*q;則下面操作正確的是 p=&x D 已知:print( )函數(shù)是一個類的常成員函數(shù),它無返回值,下列表示中,正確的是 void print( ) const 下列表示引用的方法中,正確的是已知:int a=1000; int &x=a 下列的各類函數(shù)中,友元函數(shù)不是類的成員函數(shù) 定義類的動態(tài)對象數(shù)
31、組時,系統(tǒng)只能夠自動調(diào)用該類的_無參_構(gòu)造函數(shù)對其進(jìn)行初始化。無論是什么繼承方式,派生類的成員不能訪問基類_ private _屬性的成員。表達(dá)式cout<<end1還可表示為_ Cout<<”/n” _?;惖墓谐蓡T在派生類中的訪問權(quán)限由_訪問控制_決定。C+支持的兩種多態(tài)性分別是_編譯時的_多態(tài)性和_運(yùn)行運(yùn)行時的多態(tài)性。C+中語句const char * const p=hello;所定義的指針p和它所指的內(nèi)容都不能被 _改變_。假定AB為一個類,則語句AB(AB&x);為該類復(fù)制初始化函數(shù)的原型說明。說明常成員函數(shù)時,關(guān)鍵字const寫在成員函數(shù)的_函數(shù)
32、頭_和_成員訪問運(yùn)算符_函數(shù)體_之間。在C+中,訪問一個對象的成員所用的運(yùn)算符是_成員選擇運(yùn)算符_,訪問一個指針?biāo)赶虻膶ο蟮某蓡T所用的運(yùn)算符是_成員訪問運(yùn)算符_。派生類從一個或多個以前定義的該類的_基類_繼承數(shù)據(jù)和函數(shù)。 在下面橫線處填上適當(dāng)字句,完成類中成員函數(shù)的定義。class A int * a; public: A(int aa=0) a= a=new int(aa) ; A( ) delete a ; 下面是一個函數(shù)模板,用于計算兩個向量的和。在下面橫線處填上適當(dāng)字句,完成函數(shù)模板定義。include <iostream.h>template<class T>
33、;T* f(T* a,T* b,int n) T* c= newTn _; for(int i=0;i<n;i+) ci= _ ai+bi _; return c;void main() int a5=1,2,3,4,5,b5=10,20,30,40,*p; p=f(a,b,5); for(int i=0;i<5;i+) cout<<pi<<endl;下面是類fraction(分?jǐn)?shù))的定義,其中重載的運(yùn)算符<<以分?jǐn)?shù)形式輸出結(jié)果,例如將三分之二輸出為2/3。在橫線處填上適當(dāng)字句。class fraction int den; /分子 int nu
34、m; /分母 friend ostream& operator<<(ostream&,fraction); ;ostream& operator <<(ostream& os,fraction fr) _ Cout<<den<<”/”<<num<<end1 _; return _ _ os _; float a=2; cout<<fun(a);下面是一個用戶口令檢查程序,在橫線處填上適當(dāng)語句完成程序功能。include <iostream.h>include <
35、string.h>_ Char*PASS=”wolleh” ;/定義由PASS指針?biāo)赶虻目诹顆olleh。void main() char user10;/用于存放輸入的口令 cout<<please input your password:<<endl; cin>>user _/輸入口令 if(strcmp(user,PASS)=0) cout<<your password is correct<<endl; else cout<<your password is error<<endl;在下面程序橫
36、線處填上適當(dāng)?shù)淖志?,使其輸出結(jié)果為0,56,56。include <iostream.h>class base public: _ int _func( )return 0;class derived:public base public: int a,b,c; _ void _ _ setValue(int x,int y,int z)a=x;b=y;c=z; int func( )return(a+b)*c;void main() base b; derived d; cout<<b.func( )<<,; d.setValue(3,5,7); cout
37、<<d.func( )<<,; base& pb=d; cout<<pb.func( )<<end1;給出下面程序的輸出結(jié)果。 #include<iostream >using namespace std;void fun(int &a, int &b) int p; p=a; a=b; b=p;void exchange(int &a, int &b, int &c) if( a<b ) fun(a, b); if( a<c ) fun(a, c); if( b<c
38、) fun(b, c);int main() int a=12,b=89,c=56; exchange(a, b, c); cout<<"a="<<a<<",b="<<b<<",c="<<c<<endl; return 0;答:結(jié)果是A=89 b=56 c=12請寫出下面程序段的輸出結(jié)果。#include <iostream>using namespace std;class A public: A( ) cout << &qu
39、ot;A" ;class B public:B( ) cout <<"B" ;class C: public A public: C( ) cout << "C" private: B b;int main ( ) C obj; return 0; 答:結(jié)果是 ABC從鍵盤上輸入數(shù)組s123 的各元素,并將數(shù)組s1轉(zhuǎn)置后存入數(shù)組s2中,最后輸出數(shù)組s1和數(shù)組s2的各元素。答:源程序如下:#include <iostream.h>void main() int s123,s232,i,j; for(i=0;i&
40、lt;2;i+) for(j=0;j<3;j+) cout<<"s1"<<i<<""<<j<<"="cin>>s1ij;s2ji=s1ij; cout<<"Array s1:"<<endl; for(i=0;i<2;i+) for(j=0;j<3;j+)cout<<s1ij<<"t"cout<<endl; cout<<"Arr
41、ay s2:"<<endl; for(i=0;i<3;i+) for(j=0;j<2;j+)cout<<s2ij<<"t"cout<<endl; 測試一個名為rectangle的矩形類,其屬性為矩形的左下角與右上角兩個點(diǎn)的坐標(biāo),能計算矩形的面積。答:源程序如下:#include <iostream.h>class car;class boat private:int weight; public:boat(int w):weight(w) friend int totalweight(boat
42、 b1,car c1); ;class car private:int weight; public:car(int w):weight(w);friend int totalweight(boat b1,car c1);int totalweight(boat b1,car c1) return b1.weight+c1.weight;void main()car c1(1000);boat b1(2000);cout<<totalweight(b1,c1)<<endl;C+是 既支持面向?qū)ο蟮某绦蛟O(shè)計又支持面向過程的程序設(shè)計的混合型語言面向?qū)ο蟪绦蛟O(shè)計思想的主要特征
43、中不包括 功能分解,逐步求精若定義:string str; 當(dāng)語句cin>>str; 執(zhí)行時,從鍵盤輸入: Microsoft 考慮下面的函數(shù)原型聲明:void testDefaulParam(int a,int b=7,char z='*');下面函數(shù)調(diào)用中,不合法的是 testDefaulParam(5,'#'); 下列語句中,將函數(shù)int sum(int x, int y)正確重載的是 float sum(float x, float y); 下列表示引用的方法中,正確的是:已知:int a=1000; int &x=a;在一個函數(shù)中,
44、要求通過函數(shù)來實(shí)現(xiàn)一種不太復(fù)雜的功能,并且要求加快執(zhí)行速度,選用 內(nèi)聯(lián)函數(shù)下列有關(guān)C+類的說法中,不正確的是 在類中,如果不做特別說明,所有成員的訪問權(quán)限均為公用的已知X類,則當(dāng)程序執(zhí)行到語句:X array3;時,調(diào)用了3次構(gòu)造函數(shù)。下面說法中,正確的是 一個類只能定義一個析構(gòu)函數(shù),但可以定義多個構(gòu)造函數(shù)已知:print( )函數(shù)是一個類的常成員函數(shù),它無返回值,下列表示中,正確的是 void print( ) const;下面描述中,表達(dá)錯誤的是 公用繼承時基類中的private成員在派生類中仍是private的設(shè)置虛基類的目的是 消除二義性 下面 基類的對象可以賦值給派生類的對象的敘述不
45、符合賦值兼容規(guī)則關(guān)于虛函數(shù)的描述中,正確的是 基類中說明了虛函數(shù)后,派生類中與其對應(yīng)的函數(shù)可不必說明為虛函數(shù)下面關(guān)于友元的描述中,錯誤的是 類與類之間的友元關(guān)系可以繼承下列關(guān)于靜態(tài)數(shù)據(jù)成員的說法,不正確的是 靜態(tài)數(shù)據(jù)成員不是所有對象所共用的如果表達(dá)式+i*k中的“+”和“*”都是重載的友元運(yùn)算符,若采用運(yùn)算符函數(shù)調(diào)用格式,則表達(dá)式還可以表示為 operator*(operator+(i),k)下面對模板的聲明,正確的是 template<class T1, class T2>下列的各類函數(shù)中,(友元函數(shù) )不是類的成員函數(shù)在類中必須聲明成員函數(shù)的 原理 ,成員函數(shù)的 實(shí)現(xiàn) 部分可以
46、寫在類外。如果需要在被調(diào)函數(shù)運(yùn)行期間,改變主調(diào)函數(shù)中實(shí)參變量的值,則函數(shù)的形參應(yīng)該是 引用 類型或 指針類型。 抽象 類只能作為基類使用,而不能聲明它的對象。進(jìn)行函數(shù)重載時,被重載的同名函數(shù)如果都沒有用const修飾,則它們的形參個數(shù)或 類型 必須不同。通過一個 常 對象只能調(diào)用它的常成員函數(shù),不能調(diào)用其他成員函數(shù)。函數(shù)的遞歸調(diào)用是指函數(shù)直接或間接地調(diào)用 自身 ??截悩?gòu)造函數(shù)的形參必須是 本類對象的引用 。在字長為32位的機(jī)器中,sizeof(char) 1 字節(jié),sizeof(unsigned int) 4 字節(jié)C+語法規(guī)定,任何變量在使用前必須先 定義 ;變量有兩個值,一個是變量本身的值,
47、另一個是變量的 地址值 。靜態(tài)數(shù)據(jù)成員是類的所有對象中 共享 的成員,靜態(tài)數(shù)據(jù)成員初始化與一般數(shù)據(jù)成員初始化 不同 。請補(bǔ)充完成下面下劃線的程序部分。#include <iostream>using namespace std;class Apublic:void f()cout<<"Call A's function f()"<<endl;class Bpublic:void f() cout<<"Call B's function f()"<<endl;void g() co
48、ut<<"Call B's function g()"<<endl; ;class C: Public Apublic:void g()cout<<"Call C's function g()"<<endl;int main()C cc;cc.B:f(); cc.B:g();cc.g();public B;閱讀下列程序,請完成劃線部分語句。#include <iostream.h>void main() int a = 50 , b(0) ; b=+a; cout<<
49、a<<","<<b<<endl; b=a+;cout<<a<<","<<b<<endl;下面是一個用戶口令檢查程序,在橫線處填上適當(dāng)語句完成程序功能。include <iostream.h>include <string.h>_ Char*PASS=”wolleh” ;/定義由PASS指針?biāo)赶虻目诹顆olleh。void main() char user10;/用于存放輸入的口令 cout<<please input your pas
50、sword:<<endl; cin>>user _/輸入口令 if(strcmp(user,PASS)=0) cout<<your password is correct<<endl; else cout<<your password is error<<endl;以下程序輸出結(jié)果為3和4,請?zhí)钌蟿澗€上的語句。#include <iostream.h>void main() Char flag=c ; switch(flag)case 'a' :cout<<"1"
51、<<endl ;case 'b' :cout<<"2"<<endl ; break;case 'c' : cout <<"3"<<endl ; default : cout <<"4"<<endl ; break; 閱讀下列程序,請將程序補(bǔ)充完整。#include <iostream.h>class Apublic:A();A(int i,int j);A()cout<<"Donstru
52、ctor.n"void print();Private:int a,b;A:A()a=b=10;cout<<"Default constructor.n"A:A(int i,int j)a=i b=j; cout<<"Constructor.n"void A:print()cout<<"a="<<a<<",b="<<b<<endl;void main()A m,n(15,18);m.print();n.print();閱讀
53、下列程序?qū)懗鏊妮敵鼋Y(jié)果。# include <iostream.h># include <string.h>void main() char *a5="student","worker","cadre","soldier","peasant" char *p1,*p2;
54、60; p1=p2=a0; for (int i=0; i<5; i+) if (strcmp(ai,p1)>0) p1=ai; if (strcmp(ai,p2)<0) p
55、2=ai; cout <<p1<<' '<<p2<<endl;答:輸出結(jié)果是:worker:cardre請寫出下面程序段的輸出結(jié)果?# include <iostream.h>int a=5;void main() int a=10,b=20; cout&
56、#160;<<a<<' '<<b<<endl; int a=0,b=0; for (int i=1; i<6; i+) a+=i; b+=a; cout <<a<<
溫馨提示
- 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 共建電站合同范本
- 場地服務(wù)合作合同范本
- 汽車出口貿(mào)易合同范本
- 車輛抵押欠款合同范本
- 在農(nóng)村買土地合同范本
- 醫(yī)藥銷售人員合同范本
- 單位圍墻改造工程合同范本
- 勞動合同范本小企業(yè)
- 專家工作合同范本模板范文
- 合同范例電視劇
- 《高血壓5項化驗》課件
- 一中師德考核評估制度
- 肋骨骨折護(hù)理個案查房
- 分布式網(wǎng)絡(luò)處理方案
- CNAS-CL02-A001:2023 醫(yī)學(xué)實(shí)驗室質(zhì)量和能力認(rèn)可準(zhǔn)則的應(yīng)用要求
- 血管外科護(hù)理課件
- 鐵路機(jī)車檢修坑施工方案
- 數(shù)字化轉(zhuǎn)型中的知識管理
- 安徽高中畢業(yè)生登記表
- 看不見的森林
- 安全用梯專題培訓(xùn)
評論
0/150
提交評論