云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 四川大学C++面向对象程序设计模拟试题1

四川大学C++面向对象程序设计模拟试题1

  • 62 次阅读
  • 3 次下载
  • 2026/4/24 2:07:02

cout << x << endl; cout << y << endl; } void Print() const { cout << z << endl; }

private: int x, y; const int z; };

int main() { Test obj1; obj1.Print(); Test obj2(1, 6, 8); obj2.Print(); const Test obj3(6, 0, 18); obj3.Print(); cout << endl; return 0; }

上面程序的输出结果为:0 0 1 6

5.阅读下面程序,写出输出结果。 #include using namespace std;

class MyClass {

private: static int n;

public: MyClass() { n += 1; } 18

~MyClass() { n -= 1; } static int GetNum() { return n; } };

int MyClass::n = 0;

int main() { cout << MyClass::GetNum() << endl; MyClass obj; cout << MyClass::GetNum() << endl; MyClass *p = new MyClass; cout << MyClass::GetNum() << endl; delete p; cout << MyClass::GetNum() << endl; cout << \ return 0; }

上面程序的输出结果为:0 1 2 1 end

6.阅读下面程序,写出输出结果。 #include using namespace std;

class A {

private: int a;

public: A() { cout << \无参构造函数\ A(int a) { cout << \含参构造函数a=\ A(const A ©): a(copy.a) { cout << \复制构造函数\ ~A() { cout << \析构函数\ };

int main() { A obj1, obj2(1), obj3(obj2); return 0; }

上面程序的输出结果为:无参构造函数 含参构造函数a=1 复制构造函数 析构函数 析构函数 析构函数

四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。

1.将如下程序补充完整。 #include using namespace std;

class Test {

private: int num;

public: Test(int num = 0) { [1] this->num或Integer::num = num; } 据成员num为形参num int GetNum() const { return num; } };

int main() { Test obj; cout << obj.GetNum() << endl; return 0; }

2.将如下程序补充完整。

#include using namespace std;

class A {

private: int a;

public: A(int m): a(m) {} void Show() const { cout << a << endl; } };

//初始化数

class B: A {

private: int b;

public: B(int m, int n = 0): [2] A(m), b(n) {} // 初始化数据成员b的值为n void Show() const { A::Show(); cout << b << endl; } };

int main() { B obj(8); obj.Show(); return 0; }

3.下列程序的输出结果为: 0 1 0

试将程序补充完整。

#include using namespace std;

class Point {

private: int x, y; static int count;

public: Point(int m = 0, int n = 0): x(m), y(n) { count++; } ~Point() { count--; } int GetX() const { return x; } int GetY() const { return y; } static void ShowCount() { cout << count << endl; } };

  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

cout << x << endl; cout << y << endl; } void Print() const { cout << z << endl; } private: int x, y; const int z; }; int main() { Test obj1; obj1.Print(); Test obj2(1, 6, 8); obj2.Print(); const Test obj3(6, 0, 18); obj3.Print(); cout << endl; return 0; } 上面程序的输出结果为:0 0 1 6 5.阅读下面程序,写出输出结果。 #include using

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com