为使该程序执行结果为10,那么应该在程序划线处填入的语句是( )。 #include<iostream> using namespace std; class MyClass { public: MyClass (int a) { x=a; } ___________ //取x值 private: int x; }; int main() { MyClass my(10); cout<<my.GetNum()<<end1; return 0; }
A.return x;
B.int GetNum(){ return x;}
C.intreturn x;
D.void GetNum(){return x;}
第1题:
有如下程序: #include<iostream> using namespace std; class Base { public: void fun() { cout<<"Base::fun"<<endl; } }; class Derived: public Base { public: void tim() } ____________ cout<<"Derived:: fun"<<endl; } }; int main() { Derived d; d.fun(); return O; } 已知其执行后的输出结果为: Base::fun Derived::fun 则程序中下划线处应填入的语句是
A.Base.fun();
B.Base::fun();
C.Base->fun();
D.fun();
第2题:
在下列的程序的横线处填上适当的语句,使该程序的输出为12。
include<iostream.h>
using namespace std;
class Base
{
public:
int a,b;
Base(int i){a=i;}
};
class Derived:public Base
{
int a;
public:
Derived(int x):Base(x),b(x+1){};
void show()
{
第3题:
【填空题】在下面程序下划线处填上适当内容,使程序执行结果为: 200________100 #include <iostream> using namespace std; Template(1____) T f(T x, T y){ if (sizeof(T) == (2____)) return x + y; else return x*y; } void main() { cout << f(10, 20) << "--" << (45.5, 54.5) << endl; }
第4题:
为完成下面的程序,应在划线处填入的语句是( )。 #include <iostream> using namespace std; class Base { private: int x; public: Base(int i) { x=i; } ~Base(){} }; class Derived : public Base { public: _______________ //完成类Derive构造函数的定义 }; int main() { Derived Obj; return 0; }
A.Derived(int i):Base(i){}
B.Derived(){}
C.voidDerived(int i):Base(0){}
D.Derived(int i){Base(i);}
第5题:
在下面的程序的横线处填上适当的语句,使该程序的输出结果为12。
include<iostream>
using namespace std;
class TestClass
{
public:
int a,b;
TestClass(int i,int j)
{
a=i;
b=j;
}
};
class TestCla