2015年电大C++语言程序设计期末复习题资料小抄【含答案】 _第1页
2015年电大C++语言程序设计期末复习题资料小抄【含答案】 _第2页
2015年电大C++语言程序设计期末复习题资料小抄【含答案】 _第3页
2015年电大C++语言程序设计期末复习题资料小抄【含答案】 _第4页
2015年电大C++语言程序设计期末复习题资料小抄【含答案】 _第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

电大 C+语言程序设计期末复习题及答案小抄资料 一、单项选择题 1、 面向对象程序设计数据与 _放在一起,作为一个相互依存、不可分割的整体来处理。 A、对数据的操作 B、信息 C、数据隐藏 D、数据抽象 2、 已知: int a=1,b=2,c=3,d=4,则表达式 ab?a: cd?c: d 的值为 _。 A、 1 B、 2 C、 3 D、 4 3、下列 while 循环的次数是 _。 while( int i=0 ) i- -; A、 0 B、 1 C、 5 D、无限 4、以下程序的输出结果是 _。 #include fuc( char* s) char* p=s; while( *p) p+; return (p-s); main() coutfuc(ABCDEF); A、 3 B、 6 C、 8 D、 0 5、 _的功能是对对象进行初始化。 A、析构函数 B、数据成员 C、构造函数 D、静态成员函数 6、下列引用的定义中, _是错误的。 A、 int i; B、 int i; C、 float i; D、 char d; int& j=i; int &j; float& j=i; j=i; char &k=d; 7、若类 A 和类 B 的定义如下: class A int i,j; public: void get(); /. ; class B: public A int k; public: make(); /. ; void B:make() k=i*j; 则上述定义中, _是非法的表达式。 A、 void get(); B、 int k; C、 void make(); D、 k=i*j; 8、以下程序段 _。 int x = -1; do x = x*x; while( !x ); A、是死循环 B、循环执行 2 次 C、循环执行 1 次 D、有语法错误 9、对定义重载函数的下列要求中, _是错误的。 A、要求参数的个数不同 B、要求参数中至少有一个类型不同 C、要求参数个数相同时,参数类型不同 D、要求函数的返回值不同 10、一个 _允许用户为类定义一种模式,使得类中的某些数据成员及某些成员函数的返回值能取任意类型。 A、函数模板 B、模板函数 C、类模板 D、模板类 ( Key:1-5:AAABC 6-10:BDCDC) 二、填空题 1、在 C+类中可以包含 、 和 三种具有不同访问控制权的成员。( Key:公有或 public,保护或 protected,私有或 private) 2、以下程序的执行结果是 _。 #include void func( int ); void func( double ); void main( ) double a=88.18; func(a); int b=97; func(b); void func( int x ) coutxendl; void func( double x ) coutx, ; (Key: 88.18, 97) 3、类中的数据和成员函数默认访问类型为 _。 (Key:私有或 private) 4、以下程序的执行结果是 _。 #include using namespace std; f(int b,int n) int i,r=1; for( i=0;i=n;i+ ) r=r*bi; return r; int _tmain() int x,a = 2,3,4,5,6,7,8,9; x=f(a,3); coutx=xendl; return 0; (Key: x=120) 5、在类内部定义的 _数据不能被不属于该类的函数来存取,定义为 _的数据则可以在类外部进行存取。 (Key:private 或 私有 或 protected 或 保护; public 或 公有 ) 6、下列程序输出的结果是 _。 #include using namespace std; void sub( char a,char b ) char c=a; a=b; b=c; void sub( char* a,char b ) char c=*a; *a=b; b=c; void sub( char* a,char* b ) char c=*a; *a=*b; *b=c; int _tmain() char a=A,b=B; sub(&a,&b); coutabendl; return 0; (Key: BA) 7、下列程序输出的结果是 _。 #include using namespace std; void Exchange( int* pFirst,int* pLast ) if( pFirstpLast ) int Change = *pFirst; *pFirst = *pLast; *pLast = Change; Exchange(+pFirst,-pLast); void Print( int Integer,int HowMany) for( int Index=0; IndexHowMany; Index+ ) coutIntegerIndex ; coutendl; int _tmain() int Integer = 1,2,3,4; Exchange(&Integer0,&Integer3); Print(Integer,4); return 0; (Key: 4 3 2 1) 8、下列程序输出的结果是 _。 #include using namespace std; int _tmain() int nInteger = 5, &rInteger = nInteger; rInteger = nInteger+1; coutnInteger,rIntegerendl; return 0; (Key: 6,6) 9、 _是一种特殊的成员函数 ,它主要用来为对象分配内存空间 ,对类的数据成员进行初始化并进行对象的其他内部管理操作。 (构造函数 ) 10、下列程序输出的结果是 _。 #include using namespace std; int _tmain() int x=2,y=3,z=4; cout( xy ) & ( !z ) | (x*y) )endl; return 0; (Key:1) 三、程序分析:给出程序运行后的输出结果 (每小题 5 分 ,共 20 分 ) 1、 #include using namespace std; int _tmain() int x=1,y=2,z=3; x+=y+=z; cout(xy?y:x),; cout(xy?x+:y+),; coutyendl; return 0; Key: 6,5,6 2、 #include using namespace std; void func( int b ); void main() int a = 5,6,7,8 ,i; func(a); for( i=0; i4; i+ ) coutai ; void func( int b ) int j; for( j=0; j4; j+ ) bj = 2*j; Key: 0 2 4 6 3、 #include using namespace std; class CSample int i; public: CSample(void); CSample(void); CSample(int val); void Print(void); ; CSample:CSample(void) coutConstructor1endl; i=0; CSample:CSample(int val) coutConstructor2endl; i=val; void CSample:Print(void) couti=iendl; CSample:CSample(void) coutDestructorendl; int _tmain() CSample a,b(10); a.Print(); b.Print(); return 0; Key: Constructor1 Constructor2 i=0 i=10 Destructor Destructor 4、 #include using namespace std; class CData protected: int nInteger; public: CData( int Integer ); CData( void ); void Print(void); ; CData:CData( int Integer ) : nInteger(Integer) coutConstructing a dataendl; CData:CData( void ) coutDestructing a dataendl; void CData:Print(void) coutThe data is nIntegerendl; class CNumber : public CData protected: double fNumber; public: CNumber(int Integer,double Number); CNumber(void); void Print(void); ; CNumber:CNumber( int Integer,double Number ) : CData( Integer ) , fNumber(Number) coutConstructing a numberendl; CNumber:CNumber( void ) coutDestructing a numberendl; void CNumber:Print(void) CData:Print(); coutThe number is fNumberendl; int _tmain() CNumber Number(1,3.8); Number.Print(); return 0; Key: Constructing a data Constructing a number The data is 1 The number is 3.8 Destructing a number Destructing a data 四、根据要求完成程序 1、完成以下程序,求 1!+2!+3!+4!+5!+6!+7!+8!+9!+10!之和。 #include using namespace std; int _tmain() long Term=_ ,Sum=_; for( int Index=1; Index=_; Index+) Term *=_; Sum +=_; coutSum of factorial from 1 to 10 is ; coutSumendl; return 0; Key:1 0 10 Index Term 2、完成下面程序,计算三角形和正方形的面积。设三角形和正方形的宽为 fWidth,高为 fHeight,则三角形的面积为 fWidth*fHeigth/2。 #include using namespace std; class CShape public: CSquare:CSquare(double Width,double Height) :_ double CSquare:Area(void) _; int _tmain() CTriangle Triangle(16,8); coutThe area of triangle is Triangle.Area()endl; CSquare Square(13,8); coutThe area of square is Square.Area()endl; return 0; Key: fWidth(Width) CShape(Width,Height) return fWidth*fHeight/2 CShape(Width,Height) return fWidth*fHeight 五、用面向对象方法设计一个阶乘类 CFactorial,在 CFactorial 类的构造函数 CFactorial(long Integer)中 ,将 Integer 的值赋给 nInteger;在主函数 int _tmain(),键盘输入任一整数 Integer,以 Integer 的值为实际参数构造一个阶乘对象 Factorial, 调用对象 Factorial 的相应成员函数输出 nInteger 的阶乘值fFactorial。完成以下函数的代码设计: ( 1)、设计构造函数 CFactorial(long Integer),求出 nInteger 的阶乘值 fFactorial。若 nInteger 没有阶乘值,则 fFactorial 赋值为 0。 ( 2)、设计 CFactorial 类的成员函数 void Print(void),输出 nInteger 的阶乘值 fFactorial。若 nInteger没有阶乘,则输出 nInteger 没有阶乘的信息。 #include using namespace std; class CFactorial public: CFactorial(long Integer); protected: long nInteger; float fFactorial; public: void Print(void); ; CFactorial:CFactorial(long Integer) : nInteger(Integer) /作答处 void CFactorial:Print(void) /作答处 int _tmain() long

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论