C++练习题(附答案)

上传人:ldj****22 文档编号:28910399 上传时间:2018-01-20 格式:DOC 页数:33 大小:186.50KB
返回 下载 相关 举报
C++练习题(附答案)_第1页
第1页 / 共33页
C++练习题(附答案)_第2页
第2页 / 共33页
C++练习题(附答案)_第3页
第3页 / 共33页
C++练习题(附答案)_第4页
第4页 / 共33页
C++练习题(附答案)_第5页
第5页 / 共33页
点击查看更多>>
资源描述

《C++练习题(附答案)》由会员分享,可在线阅读,更多相关《C++练习题(附答案)(33页珍藏版)》请在金锄头文库上搜索。

1、5.9(11)下列关于 C+函数的叙述中,正确的是 A)每个函数至少要具有一个参数 B)每个函数都必须返回一个值 C)函数在被调用之前必须先声明 D)函数不能自己调用自己 (12)下列关于类和对象的叙述中,错误的是 A)一个类只能有一个对象 B)对象是类的具体实例 C)类是对某一类对象的抽象 D)类和对象的关系是一种数据类型与变量的关系 (13)在 C+中,用于实现运行时多态性的是 A)内联函数 B)重载函数 C)模板函数 D)虚函数 (14)下列关于运算符重载的叙述中,正确的是 A)通过运算符重载,可以定义新的运算符 B)有的运算符只能作为成员函数重载 C)若重载运算符+ ,则相应的运算符函

2、数名是+ D)重载一个二元运算符时,必须声明两个形参 (15)下列关于模板的叙述中,错误的是 A)模板声明中的第一个符号总是关键字 template B)在模板声明中用括起来的部分是模板的形参表 C)类模板不能有数据成员 D)在一定条件下函数模板的实参可以省略 (16)对于语句 cout void fun(int int main() int a2=23,42; fun(a1,a0); std:cout T func(T x,T y) return x*x+y*y; 在下列对 func 的调用中,错误的是 A)func(3,5); B)func(3.0,5.5); C)func(3,5.5);

3、 D)func(3,5.5); (27)在下列函数原型中,可以作为类 AA 构造函数的是 A)void AA(int); B)int AA(); C)AA(int)const; D)AA(int); (28)下列关于 this 指针的叙述中,正确的是A)任何与类相关的函数都有 this 指针 B)类的成员函数都有 this 指针 C)类的友元函数都有 this 指针 D)类的非静态成员函数才有 this 指针 (29)有如下程序: #include using namespace std; class Test public: Test() n+=2; Test() n-=3; static

4、int getNum() return n; private: static int n; ; int Test:n=1; int main() Test* p=new Test; delete p; cout using namespace std; class A public: A()cout using namespace std; class BASE public: BASE()cout using namespace std; class AA int n; public: AA(int k):n(k) int get()return n; int get()constretur

5、n n+1; ; int main() AA a(5); const AA b(6); cout using namespace std; class Point public: Point(int xx=0,int yy=0) X=xx;Y=yy;countP+; Point()countP-; int GetX()return X; int GetY()return Y; static void GetC()cout using namespace std; class Base public: _void fun()coutfun(); delete p; return 0; (12)请

6、将下列类定义补充完整。 class Basepublic: void fun()cout= (8)int Point:countP=0; (9)友元 (10)私有或 private (11)virtual (12)Base:fun( ); 6.4(11)下列关于 C+函数的说明中,正确的是 A)内联函数就是定义在另一个函数体内部的函数 B)函数体的最后一条语句必须是 return 语句 C)标准 C+要求在调用一个函数之前,必须先声明其原型 D)编译器会根据函数的返回值类型和参数表来区分函数的不同重载形式 (13)下列关于虚函数的说明中,正确的是 A)从虚基类继承的函数都是虚函数 B)虚函数不

7、得是静态成员函数 C)只能通过指针或引用调用虚函数 D)抽象类中的成员函数都是虚函数 (14)运算符重载是对已有的运算符赋予多重含义,因此 A)可以对基本类型(如 int 类型)的数据,重新定义“+”运算符的含义 B)可以改变一个已有运算符的优先级和操作数个数 C)只能重载 C+中已经有的运算符,不能定义新运算符 D)C+中已经有的所有运算符都可以重载 (15)模板对类型的参数化提供了很好的支持,因此 A)类模板的主要作用是生成抽象类 B)类模板实例化时,编译器将根据给出的模板实参生成一个类 C)在类模板中的数据成员都具有同样类型 D)类模板中的成员函数都没有返回值(18)下列语句中,错误的是

8、 A)const int buffer=256; B)const int temp; C)const double *point; D)const double *rt=new double(5.5); (20)有如下程序: #include using namespace std; int main() int *p; *p = 9; cout using namespace std; int main() void function(double val); double val; function(val); cout using namespace std; class Base pu

9、blic: void fun() coutfun(); D)fun(); (24)下面是重载为非成员函数的运算符函数原型,其中错误的是 A)Fraction operator + (Fraction, Fraction); B)Fraction operator - (Fraction); C)Fraction D)Fraction& operator += (Fraction&, Fraction); (25)有如下函数模板: template T cast(U u) return u; 其功能是将 U 类型数据转换为 T 类型数据。已知 i 为 int 型变量,下列对模板函数 cast 的

10、调用中正确的是 A)cast(i); B)cast(i); C)cast(i); D)cast(i);(26)若磁盘上已存在某个文本文件,其全路径文件名为 d:ncretest.txt,下列语句中不能打开该文件的是 A)ifstream file(d:ncretest.txt); B)ifstream file(d:ncretest.txt); C)ifstream file; file.open(d:ncretest.txt); D)ifstream* pFile = new ifstream(d:ncretest.txt); (27)有如下类定义: class Foo public: Fo

11、o(int v) : value(v) / Foo() / private: Foo() / int value = 0; / ; 其中存在语法错误的行是 A) B) C) D)(28)有如下类定义: class Point int x_, y_; public: Point(): x_(0), y_(0) Point(int x, int y =0): x_(x), y_(y) ; 若执行语句 Point a(2), b3, *c4; 则 Point 类的构造函数被调用的次数是 A)2 次 B)3 次 C)4 次 D)5 次(29)有如下类定义: class Test public: Tes

12、t() a = 0; c = 0; / int f(int a) const this-a = a; / static int g () return a; / void h(int b) Test:b = b; ; / private: int a; static int b; const int c; ; int Test:b = 0; 在标注号码的行中,能被正确编译的是 A) B) C) D)(30)有如下程序: #include using namespace std; class A public: A() cout using namespace std; class Base p

13、ublic: void fun1() cout using namespace std; class Complex double re, im; public: Complex(double r, double i) : re(r), im(i) double real() const return re; double image() const return im; Complex& operator += (Complex a) re += a.re; im += a.im; return *this; ; ostream& operator using namespace std;

14、int main() void test(int, char, double _ ); test(1, A, 10.1 ); test(2, B); return 0; void test(int a, char b, double c) cout using namespace std; class Con char ID; public: Con(): ID(A) cout using namespace std; class ONE public: virtual void f() cout f(); return 0; 执行上面程序的输出是_。(12)有如下程序: #include u

15、sing namespace std; class PARENT public: PARENT() cout T1 FUN(T2 n) return n*5.0; 若要求以 int 型数据 7 为函数实参调用该模板函数,并返回一个 double 型数据,则该调用应表示为_。 一、选择题 (11)C) (13)B) (14)C) (15)B ) (18)B) (20)D) (21)D) (22)B) (23)B) (24)C ) (25 )D ) (26)A) (27)D) (28)C) (29)D ) (30)B) (32)B) (33)D) (35)B) 二、填空题 (6)break (7)int *p=DATA (8)=3.5 (9)2 (10)13A23B (11)2213 (12)PARENTSON (14) 【14】real+a.real,imag+a.imag (15) 【15

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号