更多"为完成下面的程序,应在划线处填入的语句是 #include<iost"的相关试题:
[单项选择]为完成下面的程序,应在划线处填入的语句是
#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(inti):Base(i)
B. Derived()
C. Void Derived (inti):Base(i)
D. Denved(inti)Base(i);
[单项选择]为完成下面的程序,应在划线处填入的语句是( )。
#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(inti):Base(i)
B. Derived()
C. voidDerived(inti):Base(0)
D. Derived(inti)Base(i);
[单项选择]下列程序中划线处正确的语句是( )。
# include <iostream>
using namespace std;
class Base
public:
void fun( )cout<<"Base:: fun" <<endl;
;
class Derived:public Base
void fun( )
______ ∥显式调用基类的函数fun( )
cout<<"Derived:: fun"<<endl;
;
A. fun();
B. Base.fun();
C. Base::fun();
D. Base- >fun();
[填空题]阅读下面程序:
#include<iostream>
using namespace std;
long fib(int n)
if ( n > 2 )
return (fib(n-1)+fib(n-2));
else
return 2;
int main( )
cout<<fib(3)<<end1;
return 0;
则该程序的输出结果应该是 【8】 。
[填空题]有以下面程序:
#include <iostream>
using namespace std;
long fib(int n)
{
if (n>2)
return (fib(n-1)+fib(n-2));
else
return 2;
}
int main( )
{
cout<<fib(3)<<endl;
return 0;
}
则该程序的输出结果应该是 【12】 。
[填空题]将下面程序补充完整。
#include <iostream>
using namespace std;
class Base{
public:
【14】 fun( ){return 0;} //声明虚函数
};
class Derived:public Base{
public:
x,y;
void SetVal(int a,int b){}
int fun( ){return x+y;}
};
void 【15】 SetVal(int a,int b){x=a;y=b;} //类Derived成员函数
void main( ){
Derived d;
cout<<d.fun( )<<endl;
}
[单项选择]下面程序的执行结果为
#include"iostream"
using namespace std;
class A
int a;
public:
void Seta(int x)a=x;
void Display_a( )cout<<a<<endl;
;
class B
int b;
public:
void Setb(int x)b=x;
void Dispaly-b( ) cout<<b<<endl;
;
class C://public A,private B
private:
int c;
public:
void Setc(int x,int y,int z)
c=z;Seta(x);Setb(y);
void Display_c( ) cout<<c<<endl;
;
①void main( )
②
③ C cc;
④ cc.Seta(1);
⑤ cc.Display_a( );
⑥ cc.Setc(2,2,3);
⑦ cc.Dispaly-b( );
⑧ cc.Display_c( );
A. 输出为2 2 3
B. 有错误在第5行
C. 输出为1 2 3
D. 有错误在第7行
[单项选择]下面程序的执行结果为
#include" iostream"
using namespace std;
class A
int a;
public:
void Seta(int x) a=x;
void Display_a( ) cout < < a < < end1;
;
class B
int b;
public:
void Setb(int x) b=x;
void Dispaly_b( ) cout < < b < < end1;
;
class C://public A,private B
private:
int c;
public:
void Setc(int x,int y,int z)
c=z;Seta(x);Setb(y);
void Display_c( ) cout < < c < < end1; ; ① voidmain( ) ② ③ C cc; ④ cc.Seta(1); ⑤ cc.Display_a( ); ⑥ cc.Setc(2,2,3); ⑦ cc.Dispaly_b( ); ⑧ cc.Display_c( );
A. 输出为2 2 3
B. 有错误在第5行
C. 输出为1 2 3
D. 有错误在第7行
[填空题]在下面横线上填上适当的语句,完成程序。
#include <iostream>
using namespace std;
class Base
int x;
public:
Base(int i) x=i;
~Base( )
;
class Derived: public Base
public:
______∥完成类 Derive 构造函数的定义
;
int main( )
Derived Obj;
return 0;
在横线处应填入的语句是 【11】 。
[填空题]有以下面程序:
#include<iostream>
using namespace std;
long fib(int n)
if (n>2)
return(fib(n-1)+fib(n-2));
else
return 2;
int main( )
cout<<fib(3)<<end1;
rcturn 0;
则该程序的输出结果应该是 【12】 。
[填空题]将下面程序补充完整。
#include <iostream>
using namespace std;
class Base
public:
【14】 fun( )return 0; //声明虚函数
;
class Derived:public Base
public:
x,y;
void SetVal(int a,int b)
int fun( )return x+y;
;
void 【15】 SetVal(int a,int b)x=a;y=b; //类Derived成员函数
void main( )
Derived d;
cout<<d.fun( )<<endl;