一起答
单选

下列哪个要素不是面向对象的关键要素(  )

  • A.模块化
  • B.抽象性
  • C.封装性
  • D.继承性
参考答案
查看试卷详情
相关试题
  1. 已知一个student类,包括学姓名,成绩和等级,不含任何成员函数,process为学生信息处理类。

    class student{

    char name[10];

    int deg;

    char level[7];

    friend class process:

    public:

    student(char na[ ],int d){strcpy(name,na);deg=d;}

    } ;

    class process{

    public:

    void trans(student s[ ]){…} //根据学生成绩计算学生等级(优大于89分,良大于79分,中大于69分,及格大于59分,不及格小于60分)

    void disp(student s[ ]){…} //根据成绩降序打印所有学生信息

    };

    要求实现process类中的两个函数:

  2. 给出下面程序的输出结果

    #include ﹤iostream.h﹥

    class A{

    private:

    friend class B;

    A(int val=0):data(val),use(1){ }

    int use,data;

    };

    class B{

    public:

    A*pa;

    B(int val=0):pa(new A(val)){ }

    ~B( ){if( -- pa -﹥use==0)delete pa;}

    B(B&rhs){ ++ rhs -﹥use;pa=rhs.pa;}

    B&operator=(B&rhs);

    A*operator -﹥( ){return pa;}

    void Display( ){

    cout﹤﹤"data="﹤﹤pa -﹥data﹤﹤",use="﹤﹤pa -﹥use﹤﹤endl;

    }

    };

    B&B::operator=(B&rhs)

    {

    if(this ==&rhs)return*this;

    if( -- pa -﹥use = =0)delete pa;

    ++ rhs -﹥use;

    pa=rhs.pa;

    return * this;

    }

    int main( ){

    B b1(1),b2(b1),b3(3);

    b1.Display( );

    b2.Display( );

    b3.Display( );

    b3=b1;

    b1.Display( );

    b3.Display( );

    return 0;

  3. 给出下面程序的输出结果

    #include ﹤iostream.h﹥

    class Sample

    {

    int n;

    static int sum;

    public:

    Sample(int x){n=x;}

    void add( ){sum+=n;}

    void disp( )

    {

    cout﹤﹤"n="﹤﹤n﹤﹤",sum="﹤﹤sum﹤﹤endl;

    }

    };

    int Sample::sum=0;

    void main( )

    {

    Sample a(2),b(3),c(5);

    a.add( );

    a.disp( );

    b.add( );

    b.disp( );

    c.add( );

    c.disp( );

    }

  4. 给出下面程序的输出结果

    #include ﹤iostream.h﹥

    class example

    {

    int a;

    public:

    example(int b){a=b++;}

    void print( ){a=a+1;cout﹤﹤a﹤﹤" ";}

    void print( )const{cout﹤﹤a﹤﹤"";}

    };

    void main( )

    {

    example x(3);

    const example y(2);

    x.print( );

    y.print( );

    }

  5. 给出下面程序的输出结果

    #include ﹤iostream.h﹥

    class Sample

    {

    int x,y;

    public:

    Sample( ){x=y=0;}

    Sample(int a,int b){x=a;y=b;}

    ~Sample( )

    {

    if(x==y)

    cout﹤﹤"x=y"﹤﹤endl;

    else

    cout﹤﹤"x!=y"﹤﹤endl;

    }

    void disp( )

    {

    cout﹤﹤"x="﹤﹤x﹤﹤",y="﹤﹤y﹤﹤endl;

    }

    };

    void main( )

    {

    Sample s1(2,3);

    s1.disp( );

    }

  6. 输入一个字符串,将其逆序后输出。

    #include ﹤iostream﹥

    using namespace std;

    void main( )

    {

    char a[50];memset(a,0,sizeof(a));

    int i=0,j;

    char t;

    cin.getline(a,50,'\n';

    for(i=0, j=strlen(a)-1;i﹤_________;i++, j-- )

    {

    t=a[i];

    a[j]=t;

    }

    cout﹤﹤a﹤﹤endl;

    }

  7. 在下划线处填上适当的句子,完成函数的定义。

    #include ﹤iostream.h﹥

    class Sample

    {

    int x;

    public:

    Sample( ){ };

    _________{x=a;}

    _________{x=a.x+++10;}

    void disp( ){cout﹤﹤"x="﹤﹤x﹤﹤endl;}

    };

    void main( )

    {

    Sample s1(2),s2(s1);

    s1.disp( );

    s2.disp( );

    }

  8. 在下面程序的下划线处填上正确的语句,使其得到下面的输出结果。  x=2,y=3

    #include ﹤iostream.h﹥

    class Sample

    {

    int x,y;

    public:

    Sample( ){

    x=y=0;

    }

    Sample(int a,int b){

    x=a;

    (__________)

    }

    void disp( )

    {

    cout﹤﹤"x="﹤﹤x﹤﹤",y="﹤﹤y﹤﹤endl;

    }

    }(____­_______)

    void main( )

    {

    Sample s(2,3), *p=&s;

    p-﹥disp( );

    }

  9. 在下划线处填上适当的语句,使程序的输出结果如下:  1 2 3 4 5 6 7 8 9 10  #include ﹤iostream.h﹥

    class Sample

    {

    int A[10][10];

    public:

    int &operator( )(int,int);

    };

    int &Sample::operator( )(int x,int y)

    {

    return A[x][y];

    }

    void main( )

    {

    Sample a;

    int i, j;

    _________

    for(j=0;j﹤10;j++)

    _________

    for(i=0;i﹤10;i++)

    cout﹤﹤a(i, 1)﹤﹤ " ";

    cout﹤﹤endl;

    }

  10. 在下划线处填上适当的语句,使程序的输出结果如下:  n=30

    #include ﹤ iostream.h ﹥

    template﹤ class T ﹥

    class Sample

    {

    T n;

    public:

    Sample( ){ }

    Sample(T i){_________}

    Sample﹤T﹥&operator+(const Sample﹤T﹥&);

    void disp( ){cout﹤﹤"n="﹤﹤n﹤﹤endl;}

    };

    template﹤class T﹥

    Sample﹤T﹥&Sample﹤T﹥::operator+(const Sample﹤T﹥&s)

    {

    static Sample﹤T﹥temp;  return temp;

    }

    void main( )

    {

    Sample﹤int﹥s1(10),s2(20),s3;

    s3=s1+s2;

    s3.disp( );

    }