C++试卷

第261题

下列关于成员函数特征的描述中,错误的是()。

第262题

有如下程序,执行后的输出结果是()。

#include<iostream>
using namespace std;
class Test{
public:
    Test(){n+=2;}
    ~Test(){n-=3;}
    static int getNum(){return n;}
private:
    static int n;
};
int Test::n=1;
int main()
{
    Test*p=new Test;
    delete p;
    cout<<"n="<<Test::getNum()<<endl;
    return 0;
}

第263题

假定MyClass为一个类,那么下列的函数说明中,()为该类的析构函数。

第264题

下列情况中,不会调用拷贝构造函数的是()。

第265题

类MyClass的定义如下,若要对value赋值,则下面语句正确的是()。

class MyClass
{
public:
    MyClass(){}
    MyClass(int i){value=new int(i);}
    int*value;
};
第266题

若有如下程序,程序运行后的输出结果是()。

#include<iostream>
using namespace std;
int s=0;
class sample
{
    static int n;
public:
    sample(int i)
    {
        n=i;
    }
    static void add()
    {
        s+=n;
    }
};
int sample::n=0;
int main()
{
    sample a(2),b(5);
    sample::add();
    cout<<s<<endl;
    return 0;
}


第267题

有如下程序,该程序运行后的输出结果是()。

#include<iostream>
using namespace std;
class sample
{
private:
    int x,y;
public:
    sample(int i,int j)
    {
        x=i;
        y=j;
    }
    void disp()
    {
        cout<<"disp1"<<endl;
    }
    void disp()const
    {
        cout<<"disp2"<<endl;
    }
};
int main()
{
    const sample a(1,2);
    a.disp();
    return 0;
}
第268题

有如下类的定义,横线处的语句是()。

class TestClass
{
    ______ int x,y;
public:
    TestClass(int a=0,int b=0)
    {
        x=a;
        y=b;
    }
    static void change()
    {
        y=10;
        x=10;
    }
}

第269题

在函数中,可以用auto、extern、register和static这四个关键字中的一个来说明变量的存储类型,如果不说明存储类型,则默认的存储类型是()。

第270题

若要把函数void fun()定义为TestClass的友元函数,则应该在类TestClass的定义中加入的语句是()。

第271题

假定MyClass为一个类,则该类的拷贝构造函数的声明语句为()。

第272题

关于静态成员的描述中,错误的是()。

第273题

下列关于构造函数的描述中,错误的是()。

第274题

下面关于构造函数和析构函数的描述中,错误的是()。

第275题

下面程序的输出结果是()。

#include<iostream>
#include<math.h>
using namespace std;
class point
{
private:
    double x;
    double y;
public:
    point(double a,double b)
    {
        x=a;
        y=b;
    }
    friend double distances(point a,point b);
};
double distances(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
    point p1(1,2);
    point p2(5,2);
    cout<<distances(p1,p2)<<endl;
    return 0;
}
第276题

有以下程序,执行后的输出结果是()。

#include<iostream>
using namespace std;
class R
{
public:
    R(int r1,int r2)
    {
        R1=r1;
        R2=r2;
    }
    void print();
    void print()const;
private:
    int R1,R2;
};
void R::print()
{
    cout<<R1<<","<<R2<<endl;
}
void R::print()const
{
    cout<<R1<<","<<R2<<endl;
}
int main()
{
    R a(5,4);
    const R b(20,52);
    a.print();
    b.print();
    return 0;
}
第277题

下列关于this指针的叙述中,正确的是()。

第278题

关于this指针的说法不正确的是()。

第279题

有如下程序,若程序的输出结果是:123,则程序中横线处的语句是()。

#include<iostream>
using namespace std;
int i=1;
class Fun
{
public:
    static int i;
    int value(){ return i-1;}
    int value()const{return i+1;}
};
int Fun::i=2;
int main()
{
    int i=3;
    Fun fun1;
    const Fun fun2;
    ________;
    return 0;
}
第280题

下列关于对象概念的描述中,不正确的是()。