更多"在下面程序中,括号里应填( )。 #include <iost"的相关试题:
[单项选择]在下面程序中,括号里应填( )。
#include <iostream>
using namespace std;
class A
public:
void fun( )
cout << "Hello" << endl;
;
class B:: public A
void fun( )
( ) //调用基类的函数fun( )
tout << "HI" << endl;
;
A. fun()
B. fun()
C. A::fun()
D. A->fun(
[填空题]阅读下面程序:
#include <iostream>
using namespace std;
int fun( int a, int b)
{
int c;
c = a * b;
return c;
}
int main ( )
{
int a = 3, b = 5, c = 4, x = O;
x = fun( fun( a, b ), c );
cout<<x<<end1;
return 0;
}
其运行结果是 【9】 。
[填空题]有以下面程序:
#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;
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;
}
[单项选择]下面程序的执行结果为 #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 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 Sera(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;Sera(x);Serb(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;
void main( )
int num=0,i=8;
do
i--;
num++;
while(--i);
cout<<nun<<endl;
[单项选择]下面程序的输出结果是( )。
#include <iostream>
using namespace std;
class point
public:
point(int px=10,int py=10) x=px;y=py;
getpx( ) return x;
getpy( ) return y;
private:
int x,y;
;
void main(voiD)
point p,q(15,15);
cout<<"p点的坐标是:"<<p. getpx( )<<" ,";
cout<<p. getpy( )<<endl;
cout<<"q点的坐标是:"<<q. getpx( )<<" ,";
cout<<q. getpy( );
A. p点的坐标是:10,10
B. p点的坐标是:0,0
C. p点的坐标是:0,0
D. p点的坐标是:10,10