面向对象程序设计复习题,选择题(4)

2019-01-05 10:49

template class A {

public: T x,y,z;

void display(){cout << x << \};

void main() {

Aa1; a1.x=1 a1.y=2 a1.z=3

a1.display(); }

(23)已知程序的输出结果如下,请将程序补充完整。 Constructor called.

Default constructor called. Area is 6 Area is 0 Area is 6

#include class RectAngle {

private:

double a,b ; public:

RectAngle(){cout<<\RectAngle(double l,double s) { a=l;b=s;

cout<<\} void Set(double l,double s) { a=l;b=s; } void Area()

{ cout<<\} };

int main()

{ RectAngle Rect1(2,3) ; RectAngle Rect2;

RectAngle Rect3(Rect1) ; Rect1.Area();

Rect2.Set(0,0) ; Rect2.Area();

Rect3.Area();return 0;}

(24)程序的输出结果如下:请填空

The grade is 3

#include

class student {

private: int grade; public:

/**************** found *******************/ student(int thegra):grade(thegra){} ~student(){}

int get_grade(){return grade;} };

void main() {

int thegra=3;

student *point=new student(thegra);

cout<<\point->get_grade()<

}

(25)C++语言中的多态性是在编译时通过 函数重载 和模板体现的,在运行时是通过 虚函数 体现的。

(26)将x+y*z中的“+”用成员函数重载,“*”用友元函数重载应写为 x.operator+(operator*(y,z)) 。

(27)已知如下程序得输出结果时23,请将划线处缺失得部分补充完整。 #include class myclass{ public:

void print() cout{cout<<23;} }

int main(){

myclass *p=new myclass; __p->_print();

return 0;} }

(28)程序的输出结果如下,请将程序补充完整。

a=3 b=13 a=5 b=13 #include class T {public:

T(int x){ a=x ; b+=x;}//数据成员初始化 void display(T c)

{ cout<<\private: int a;

static int b;};

static int b=5; void main()

{T A(3),B(5) ; T::display(A);

T::display(B);}

(29)在用class定义一个类时,数据成员和成员函数的默认访问权限是_私有__。 (30)含有纯虚函数的类称为__抽象类___。

(31)定义内联函数所用的关键字 inline ,定义友元所用的关键字为 friend 。 (32) 标准模板库STL中有3个主要组件:_容器__、迭代器、算法。 (33)C++中模板分为函数模板和类模板。 (34)填空,使该程序执行结果为10。 #include class MyClass { public:

MyClass(int a){x = a;}

__int getnum(){return x;}____//取x值 private: int x; }; int main()

{ MyClass my(10);

cout<

(35)填上合适的字句,使程序的最终结果为200。 #include

class number{ public:

number(int i){val=i;} operator int( ); private: int val; };

number::operator int ( ){ return val;} class num: public number { public:

num(int i): number(i){ } }; void main( ) { num n(100); int i=n;

cout<

(36)请将如下程序补充完整,使得输出结果为bbaa #include using namespace std; class A { public:

_~A()__{cout<<”aa”;} };

class B :public A{ public:

~B(){cout<<”bb”;} };

int main (){

B *p=new B; delete p;

return 0; }

(37)程序的输出结果如下,请填空 (1,2) 5,6 (6,9)

#include class A{ public:

A(int i,int j){ a=i; b=j; }

void Move( int x, int y) {a+=x;b+=y;}

void Show() {cout <<\private : int a,b; };

class B:private A {

public:

/**************** found *******************/ B(int i,int j,int k,int l): A(i,j) {x=k;y=l;} void Show(){cout<

/**************** found *******************/ void f1(){A::Show();} private: int x,y; };

void main () {

A e(1,2); e.Show(); B d(3,4,5,6); d.fun(); d.Show(); d.f1(); }

(38)下列程序在构造函数和析构函数中申请和释放类的数据成员int *a,申请时使用形参b初始化a,请填空。

class A {

public:

A(int b); ~A(); private: int *a; };

A::A(int b)

{

a=new int(b); }

A::~A() {

delete a ;

}

(39)完成下面类中的成员函数的定义。 class test{

private: int num; float x; public: test(int n,float f); test(test&); };

test::test(int n,float f) {num=n; _x=f_; } test::test(text& t)

{ _num=t.num__; x=t.x; } (40)程序的输出结果如下, 请填空。

4 , 5 20

#include class A

{ protected:int m,n;//声明私有数据成员 public:

void set(int a,int b){m=a; n=b;}

void show(){cout<

void set(){s=m*n;}

void shows(){cout<

b.A::set(4,5) ; b.show(); b.set();

b.shows() ; return 0;}

(41)程序的输出结果如下,请填空。 f1 function of derive f2 function of base f4 function of base

#include class base {public:

virtual void f1(){ cout<<\virtual void f2(){ cout<<\virtual void f3(){ cout<<\


面向对象程序设计复习题,选择题(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2017中传电影学考研各细分专业有电影艺术史论方向吗

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

马上注册会员

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