C 面向对象程序设计模拟试题六

上传人:zw****58 文档编号:43463951 上传时间:2018-06-06 格式:DOC 页数:11 大小:46KB
返回 下载 相关 举报
C  面向对象程序设计模拟试题六_第1页
第1页 / 共11页
C  面向对象程序设计模拟试题六_第2页
第2页 / 共11页
C  面向对象程序设计模拟试题六_第3页
第3页 / 共11页
C  面向对象程序设计模拟试题六_第4页
第4页 / 共11页
C  面向对象程序设计模拟试题六_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《C 面向对象程序设计模拟试题六》由会员分享,可在线阅读,更多相关《C 面向对象程序设计模拟试题六(11页珍藏版)》请在金锄头文库上搜索。

1、C+面向对象程序设计模拟试题六面向对象程序设计模拟试题六一、单项选择题(本大题共一、单项选择题(本大题共 15 小题,每小题小题,每小题 2 分,共分,共 30 分)在每小题列出的四个备选项分)在每小题列出的四个备选项 中,只有一个是苻合题目要求的。请将其代码填写在题后的括号内。错选,多选或未选均中,只有一个是苻合题目要求的。请将其代码填写在题后的括号内。错选,多选或未选均 无分。无分。1类的析构函数的作用是( d )。A) 作为类的一般成员函数 B) 类的初始化 C) 对象的初始化 D) 对象的删除 2一个类的友元函数或友元类可以访问该类的( d )。 A) 私有成员 B) 保护成员 C)

2、公有成员 D) 所有成员 3下列关于成员函数特征的描述中,( a ) 是错误的。 A) 成员函数一定是内联函数 B) 成员函数可以重载 C) 成员函数可以设置参数的默认值 D) 成员函数可以是静态的 4下列函数中,( c ) 不是类的成员函数。 A) 构造函数 B) 析构函数 C) 友元函数 D) 拷贝构造函数 5下列对派生类的描述中,( d ) 是错误的。A) 一个派生类可以作为另一个派生类的基类B) 派生类至少有一个基类C) 派生类的成员除了它自己的成员外, 还包含了它的基类的成员D) 派生类中继承的基类成员的访问权限到派生类中保持不变 6下列的描述中,( b ) 是错误的。 A) 公有继

3、承时基类中的 public 成员在派生类中仍是 public 的B) 公有继承时基类中的 private 成员在派生类中仍是 private 的C) 公有继承时基类中的 protected 成员在派生类中仍是 protected 的D) 私有继承时基类中的 public 成员在派生类中仍是 private 的 7下列虚基类的声明中正确的是( d )。A) class virtual B: public A B) virtual class B: public AC) class B: public A virtual D) class B: virtual public A 8若类 A 和类

4、B 的定义如下:class A int i, j; public: A(int m, int n): i(m), j(n) int Geti() return i; ;class B: public Aint k; public: B(int m, int n, int u): A(m, n), k(u) void Make() k = i * j; ;int main()B b(1, 2, 3);return 0;则上述定义中,( ) 是非法的表达式. A) k=i*j; B) int k; C) return i; D) void Make( ) 9若有以下程序:#include usin

5、g namespace std;class A public: int a; A() a =10; ; class A1: public A1 public: A1() a = a + 1; ; class A2: public A public: A2() a = a + 2; ; class B: public A1, public A2 public: B() void Print() cout class A int a; public:A(int aa = 0 ) a = aa; cout class Point int x, y;public:Point(int m = 0, in

6、t n = 0) x = m; y = n; void Show() cout Show();delete p;return 0;输出结果为:3若有以下程序:#include class Sample int n;public:Sample(int i) n = i; s += n; static int s;void Show() cout class Sample int n;public:Sample(int i) n = i; void Print() cout class Test int x; public: void Setx(int i) x = i; int Putx() r

7、eturn x; ;int main()Test *p; Test a3; a0.Setx(5); a1.Setx(6); a2.Setx(7);for( int j = 0; j Putx() class Basepublic: Base(int x) a = x; void Show() cout Show(); return 0;输出结果 为: 7若有以下程序:#include class Base public:void Fun() cout template class FF TT a1,a2,a3;public:FF(TT b1,TT b2, TT b3) a1 = b1; a2

8、= b2; a3 = b3; TT Sum() return a1 + a2 + a3; ;int main()FF x(2, 3, 4), y(5, 7, 9);cout using namespace std;class Rect private:double length, width; public: Rect(double l = 0, double w = 0): length(l), width(w) void Set(double l, double w) if (length = 50 | width = 50 ) throw “数据不在指定范围(0,50)!“;/ 抛出异常

9、length = l;width = w;double GetPerimeter() return 2 * (length + width); ;int main() try/ 检查异常Rect obj(1, 8);cout using namespace std;class Vector2d double x, y; public: Vector2d(double a, double b): x(a), y(b) void Show() cout x “ “ y endl; Vector2d operator+(Vector2d ;Vector2d Vector2d:operator+(Vector2d int main() Vector2d d1(3.5, 4.5), d2(2.5, 5.5), d3(0.0, 0.0);d3 = d1 + d2; d3.Show(); return 0;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

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