设为首页 加入收藏

TOP

华中科技大学计算机学院《面向对象程序设计》考试试卷
2011-04-24 21:59:52 来源: 作者: 【 】 浏览:788
Tags:华中 科技 大学 计算机 学院 《面向对象程序设计》 考试 试卷
一. 单选题(共15分,每小题3分)。
 
1.包含纯虚函数的类是_____。
(A) 基类。 (B) 派生类。 (C) 抽象类。 (D) 虚基类。
2.对A *p用new A或(A *)malloc(sizeof (A))赋值,如下叙述正确的是_____。
(A) new分配内存后会调用构造函数初始化,但malloc函数不会。
(B) malloc分配内存后会调用构造函数初始化,但new函数不会。
(C) new和malloc分配内存后都会调用构造函数初始化。
(D) new和malloc分配内存后都不会调用构造函数初始化。
3.表达式“sizeof(int [1][2])/sizeof(int)”的值为_____。
(A)  1。  (B)  2。  (C)  3。 (D)  4。
4.类A定义了构造函数A( )、A(int)、A(int,int)、A(int,int,int),则new  A[2][3]会调用_____。
(A)  A( )。 (B)  A(int)。 (C)  A(int, int)。(D) A(int, int, int)。
5.指向类A的一个非静态整型只读成员的非只读指针p定义为_____。
(A)  const  int  A::*const  p; 
(B)  int  A::* const  p;
(C)  int  A::* p;
(D)  const  int  A::* p;

 
得分 评卷人

二. 指出以下各类可访问的成员及其访问权限(共20分,小题分数各为3分、3分、6分、8分)。 
(1)  class  A{
int  m;
private:
int  n;
protected:
int  o;
public:
int  p;
};
(2) struct B: A{
int  a;
protected:
int  b;
A::o;
public:
int  c;
A::p;
};
(3) struct C: A{
int  a;
private:
int  b;
protected:
int  c;
public:
int  d;
};
(4) class D: protected B, C{
int  e;
private:
int  f;
protected:
int  g;
public:
int  h;
};
 

 
得分 评卷人

三. 指出main中每行的输出结果(共20分,每行的分值依次为1,2,3,4,5,5分)。
 
#include <iostream.h>
struct A{A( ){ cout<<'A';}};
struct B{A  a;   B( ):a( ){ cout<<'B';}};
struct C: A{ B  b;  C( ):A( ){ cout<<'C';}};
struct D: virtual B, virtual C{B  b;  D( ){ cout<<'D';}};
struct E: A, C{
    D  d;
    E( ):d( ){ cout<<'E';}
};
struct F: virtual B, C, virtual D, E{
    E   e;
    F( ):E( ), e( ){ cout<<'F';}
};
void main( ){
    A  a;  cout<<' '; //输出=
    B  b;  cout<<' ';  //输出=
    C  c;  cout<<' ';  //输出=
    D  d;  cout<<' ';  //输出=
    E  e;  cout<<' ';  //输出=
F  f ;  cout<<' ';  //输出=
}

 
得分 评卷人

四. 指出以下程序的语法错误及其原因(共15分,每个错误大约1分)。
 
typedef  int * CP;
class  A{
    int  a;
protected:
    static int  g ( )volatile{ return  2; };
public:
    const  int  c;
    A(int x) { a=c=x; };
    virtual operator int( ){ return  a+c; };
} a=2;
struct B: A{
    int  d;
public:
    A::g;
    B(int x){ d=x;} ;
} b=(2,3);
class C: B{
    int  e;
    virtual  C( ){ e=0; };
    virtual ~C( ){ };
}c, *const p;
const  CP  r;
void main( ){
    int  A::**const*q, i;
    i=a.a;
    i=A(B(i));
    b.c=b+c;
    q=&A::c;
    i=a.****q;
    return i;
}

 
得分 评卷人

五. 指出main变量i在每条赋值语句执行后的值(共15分,每个i值大约2分)。
 
int   x=2,  y=x+3;
struct A{
    int  x;
    static int  y;
public:
    operator int( ){ return x*y; }
    int &h(int &x){
        for(int  y=x; x<2*y; x+=5, y+=2) if (x>3*y+7) x-=y;
        return  x;
    }
    A &operator ++( ){ x++;  y++;  return *this; }
    A(int x=3, int y=::y+2): x(x+::x) { this->y=y; }
};
int A::y=::y;
void main( ){
    A  a(3,2),  b(7),  c;
    int  i,  &m=i,  A::*p=&A::x;
    i=A::y; //i=
    m=b.x; //i=
    i=b.*p; //i=
    i=b+A(A(3)); //i=
    m=++a; //i=
    b.h(m)=9; //i=
    i=b.h(m)-c.x; //i=
}

 
得分 评卷人

六. 如图所示,用对顶生长的双栈模拟一个队列,栈1的入栈作为队列元素的入口(队尾),栈2的出
 
栈作为对列元素的出口(队首)。当栈2非空时,不得将栈1的元素弹出压入栈2;只有在栈2为空时,才能将栈1的元素弹出压入栈2,且必须全部弹出压入栈2。编写队列类QUEUE中的所有函数 (共15分,每个函数2.5分)。
 
class QUEUE{
    int   *const  e; //用于存放队列元素
    int    p1, p2;         //双栈中栈1和栈2的顶(当前空位)
    const  int  m;          //队列能存放的最大元素个数
public:
    QUEUE (int  m);        //一共能存放的最大元素个数m
    QUEUE (const QUEUE &t); //用队列对象t构造一个新对象
    virtual QUEUE & operator = ( const QUEUE &b); //队列对象赋值
    virtual QUEUE & operator << ( int  k); //元素k放入队列
    virtual QUEUE & operator >> ( int  &k); //从队列取出元素放入k
    virtual ~ QUEUE ( );
};
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2011年3月计算机等级考试二级C++.. 下一篇没有了

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: