一起答
单选

已知f和g是同一类中的两个成员函数,若f的实现代码体内不能调用g则可能的情况是()

  • A.f和g都是常成员函数
  • B.f是常成员函数,g不是
  • C.f不是常成员函数,g是常成员函数
  • D.g和f都不是常成员函数
参考答案
查看试卷详情
相关试题
  1. 写一个程序,定义一个抽象类Shape,由它派生3个类Square(正方形),Trapezoid(梯形)和Triangle三角形。用虚函数分别计算几种图形面积并求它们的和。要求用基类指针数组,使它的每一个元素指向一个派生类对象。

    #include

    class Shape

    {public:

    virtual double area()const=0;

    };

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

    #include

    class A

    {private:

    int a;

    public:

    void set(int x){a=x;}

    void show()cout<<"a="<

    };

    class B:public A

    {private:

    int b;

    public:

    void set(int x=0){A::set(x);b=x+10;}

    void set(int x,int y){A::set(x);b=y;}

    void show(){A::show();cout<<"b="<

    };

    void main()

    {B b;

    b.set(10);b.show();

    b.set(30,50);b.show();

    }

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

    #include

    template

    class Num

    {T x,y;

    public:

    Num(T i,T j=0){x=i;y=j;}

    void set(T i,T j=0){x=i;y=j;}

    void show()

    {cout<

    if(y!=0)

    cout<<(y>0'+':'-')<<(y>0?y:-y)<'i';

    cout<

    }

    };

    void main()

    {Numn(1);

    n.show();

    n.set(2,3);

    n.show();

    Numm(3,-4);

    m.show();

    }

  4. 一个类的头文件如下所示,num初始化值为5,程序产生对象T,且修改num为10,并使用show()函数输出num的值10。

    #include

    class Test

    {private:

    static int num;

    public:

    Test(int);

    void show();

    };         

    _________

    Test:: Test(int n)

    {num=n;}

    void Test::show()

    {cout<

    void main()

    {Test t(10);

    _________       

    }

  5. 下面程序段用来求三角形的面积,首先进行判断,三边不符合组成三角形时,返回-1;符合时输出三角形面积。

    #include

    #include

    double area(double a,double b,double c)

    {if (_________)

    Return -1;

    else

    {

    double ar,1;

    1=(a+b+c)/2;

    ar=sqrt(1*(1-a)*(1-b)*(1-c));

    retum ar;

    }

    }

    void main()

    {double i=0,j=0,k =0;

    Cout<<”输入三角形三边:”;

    cin>>i>>j>>k;

    double s=area(i,j,k);

    if(s<0)

    cout<<"不是三角形"<

    else

    __________

    }

  6. 在下面横线处填上求两个浮点数之差的cha函数的原型声明、调用方法。

    #include

    using namespace std;

    void main()

    {float a,b;

     _________//函数cha的原型声明

    a=12.5;

    b=6.5;

    float c=_________;//调用函数cha

    cout<

    }

    float cha( float x, float y)

    {float w;

    w=x-y;

    return w;

    }

  7. 下面程序中用来求数组和。请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为s=150。

    #include

    class Arr

    {int*a,n;

    public:

    Arr():a(0),n(0){}

    Arr(int*aa,int nn)

    {n=nn;

    a=new int[n];

    for(int i=0;i

    *(a+i)=*(aa+i);

    }

    ~Arr(){deletea;}

    ____________

    {return*(a+i);}

    };

    void main()

    {int b[5]={10,20,30,40,50}

    Arr a1(b,5);

    int i=0,s=0;

    ____________

    s+=a1.GetValue(i);

    cout<<"s="<

    }

  8. #include

    class Base

    {protected:

    int x;

    public:

    virtual void fun()=0;

    }

    class Derived:public Base

    {int z;

    public:

    Derived(int i){z=5;}

    void fun()

    cout<<"派生类fun():"<<"z="<

    };

    void main()

    Derived b(5);

    Base*p=new Base(6);

    p= &b;

    p->fun();

    }

  9. 写出模板函数实现数值型数组元素值按从小到大排序的程序。

    #include

    using namespace std;

    ____________

    void sort(Tb[ ],int n)

    {T temp;

    int i,j;

    T*a=newT[n];

    for(i=0;i

    {a[i]=b[i];}

    for(i=0;i

    {for(j=i+;j

    if(a[i]>a[j])

    {temp=a[i];

    a[i]=a[j];

    a[j]=temp;

    }

    }

    }

    for(i=0;i

    {cout<

    cout<

    delete a;

    }

    void main()

    {int i,n=6;

    int a[]={5,1,9,10,3,8}

    sort___________;

    for(i=0;i

    {cout<

    cout<

    }

  10. #include

    class A

    {private:

    int x;

    protected:

    int y;

    public:

    A(int i,int j){x=i;y=j;}

    };

    class B:public A

    {public:

    B(int a,int b):A(a,b){}

    void show()cout<

    };

    void main()

    {B b(8,9);

    B.show();

    }