C++面向对象程序设计模拟试题五(2)

2019-08-03 12:02

int main() {

double d; int i ; d = 99.99; i = 88; Fun(d,i);

cout << \return 0;

}

上面程序的输出结果为:

6.阅读下面程序,写出输出结果。

#include using namespace std;

class Point { public: private: };

int main(void) {

Point oPoint1;

const Point oPoint2(3, 4); cout << oPoint1.GetX() << endl; oPoint1.SetX(1);

cout << oPoint1.GetX() << endl; oPoint1.SetY(2);

cout << oPoint1.GetY() << endl; cout << oPoint2.GetX() << endl; cout << oPoint2.GetY() << endl; return 0; int m_x; int m_y;

// X坐标 // X坐标

Point (int x = 0, int y = 0): m_x(x), m_y(y){ } int GetX() const { return m_x; } int GetY() const { return m_y; } void SetX(int x) { m_x = x; } void SetY(int y) { m_y = y; }

}

上面程序的输出结果为:

7. 阅读下面程序,写出输出结果。

#include class Sample { };

Sample::Sample() { }

void Sample::Display() { cout << \

Sample::~Sample() { cout << \ int main() { }

Sample a; a.Display(); return 0;

cout << \ i=0; int i; Sample(); void Display( ); ~Sample(); public:

上面程序的输出结果为:

8.阅读下面程序,写出输出结果。

#include using namespace std; class A {

int a,b;

A() { a = b = 0; } public:

};

A(int aa, int bb) { }

a = aa; b = bb;

cout << a << ' ' << b << endl;

int main() { }

A x, y(2,3); return 0;

上面程序的输出结果为:

五、 程序改错题(本大题共3小题,共3处错, 每改一错2分,共6分)指出下面程序中错误, 说明错误原因, 并加以改正。

1.下面程序中类的定义中有一处错误,请指出出错的行,说明错误原因,并加以改正。

#include using namespace std; { }; { }

class A public:

//1 //2 //3 //4 //5 //6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 //17 //18

A(int i = 0, int j): mi(i), mj(j) {} void Show()

int mi, mj;

{ cout << mi << ' ' << mj << endl; }

private:

int main()

A obj(12,16); obj.Show(); return 0;

2.下面程序中类的定义中有一处错误,请指出出错的行,说明错误原因,并加以改正。

#include using namespace std; {

class A

//1 //2 //3 //4 //5

public: }; { }

//6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 //17 //18 //19

A(int a):m_a = a{} void Show()

{ cout << m_a << endl; } int m_a;

private:

int main()

A obj(8); obj.Show(); return 0;

3.下面程序中类的定义中有一处错误,请指出出错的行,说明错误原因,并加以改正。

#include using namespace std; { }; { }

class Test public:

//1 //2 //3 //4 //5 //6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 //17 //18 //19 //20 //21

Test(int iVar = 0):m_iArr(iVar) void ~Test()

{ cout << \构造函数:\ { cout << \析造函数:\

private:

int m_iArr;

int main()

Test obj1, obj2(8); cout << endl; return 0;

六、 编程题(本大题共2小题,每小题10分,共20分)

1.设计一个类DateInfo,要求其满足下述要求:

(1)要求有一个无参的构造函数,其初始的年、月、日分别为:2010,6,8。 (2)要求有一个带参数的构造函数,其参数分别对应年、月、日。 (3)要求用一个成员函数实现日期的设置。 (4)要求用一个成员函数实现输出日期。 要求用一个成员函数实现日期的获取。

2.定义一个复数类Complex, 二个数据成员为double型r, i 为private属性。定义代二个参数的构造函数和一个Show( ) 函数用以输出r, i的值, 另外作为成员函数重载的运算苻”+”的功能是将此类二个对象的数据成员r和i对应相加。这些成员函数的属性均为public. 请用C++编写此程序, 并编写测试程序进行测试。


C++面向对象程序设计模拟试题五(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:空气调节用制冷技术试题及答案

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: