更多"有如下程序: #include<iostream> #includ"的相关试题:
[单项选择]有如下程序:
#include<iostream>
#include<string>
using namespace std;
class Person
public:
Person(string n):name(n)cout<<’P’;
pnvate:
string name;
;
class Date
public:
Date(int y=2012,int m=12,int d=21):year(y),month(m),day(d)cout<<’D’;
private:
int year,month,day;
;
class Student:public Person
public:
Student(string n,int y,int m,int d,char c):birthday(y,m,d),sex(c),Person(n)cout<<’S’;
private:
Date birthday;
char sex;
;
int main( )
Student stul("Zhang",1990,10,1,’F’);
return 0;
运行时的输出结果是______。
A. S
B. PS
C. DPS
D. PDS
[填空题]如下程序执行后的输出结果是 【14】 。
#include <iostream>
using namespace std;
class Base
{
public:
Base(int x,int y)
{
a=x;
b=y;
}
void Show( )
{
cout<<"Base: "<<a<< ’,’ <<b<<" ";
}
private:
int a,b;
};
class Derived : public Base
{
public:
Derived(int x, int y, int z) : Base(x,y),c(z) { }
void Show( )
{
cout<<"Derived:"<<c<<end1;
}
private:
int c;
};
int main( )
{
Base b(100,100),*pb;
Derived d(10,20,30);
pb=&b;
pb->Show( );
pb=&d;
pb->Show( );
return 0;
}
[填空题]下列程序的输出结果为2,请将程序补充完整。
#include <iostream>
using namespace std;
class Base
{
public:
______void fun( ) {cout<<1;}
};
class Derived:public Base
{
public:
void fun( ){cout<<2;}
};
int main( )
{
Base*p=new Derived;
p->fun( );
delete p;
return 0;
}
[填空题]请在下列程序的横线处填写正确的语句。
#include<iostream>
using namespace std;
class Base{
public:
void fun( ){cout<<"Base fun"<<endl;}
};
class Derivde:public Base{
public:
void fun( ){
______∥ 调用基类的函数fun( )
cout<<"Derived fun"<<endl;
}
};
[填空题]在下面横线上填上适当的语句,完成程序。
#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;
}
在横线处应填入的语句是 【9】 。
[填空题]下列程序的输出结果是______。
#include <iostream>
using namespace std;
template<typename T>
T fun(T a,T b) { return (a<=b)a:b;)
int main( )
{
cout<<fun(3, 6)<<’,’<<fun(3.14F,6.28F) <<end1;
return 0;
[单项选择]下面程序有注释的语句中,错误的语句是( )。 #include <iostream> using namespace std; class A{ int a; public: void show A( ){cout<<"this is A!";} }; class B:public A{ int b; public: void showB( ){cout<<"this is B!";} }; void main( ){ A ia,*piA; B ib,*piB; piA=&ia; //第一个测试语句 piA=&ib; //第二个测试语句 piB=&ia; //第三个测试语句 piB=&ib; //第四个测试语句 }
A. 第一个测试语句
B. 第二个测试语句
C. 第三个测试语句
D. 第四个测试语句
[单项选择]应在下列程序画线处填入的正确语句是 ( )。 #include <iostream> using namespace std; clas Base { public: void fun( ) { cout<<"Base::fun"<<end1; } }; class Derived : public Base { void fun( ) { ________________//显示调用基类的函数 fun( ) cout<<"Derived::fun"<<end1; } };
A. fun();
B. Basfun();
C. Base::fun();
D. Base->fun();
[单项选择]有以下程序:
#include <iostream>
#include <math>
using namespace std;
class point
private:
double x;
double y;
public:
point(double a,double b)
x=a;
y=b;
friend double distance(point a,point b) ;
;
double distance(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 pl(1,2);
point p2 (5, 2);
cout<<distance (pl,p2) <<end1;
return 0;
程序运行后的输出结果是( )。
A. 1
B. 5
C. 4
D. 6
[单项选择]有以下程序
#include <iostream>
#include <string>
using namespace std;
class base
private:
char baseName[10];
public:
base ( )
strcpy(baseName,"Base");
virtual char *myName( )
return baseName;
char *className( )
return baseName;
;
class Derived : public base
private:
char derivedName[10];
public:
Derived( )
strcpy(derivedName,"Derived");
char *myName( )
return derivedName;
char *className( )
return derivedName;
;
void showPtr(base &p)
cout<<p.myName ( ) <<" "<<p.className ( );
int main ( )
base bb;
Derived dd;
showPtr(dd);
return 0;
运行后的输出结果为
A. Derived Base
B. Base Base
C. Derived Derived
D. Base Derived
[单项选择]有以下程序:
#include<iostream>
#include<string>
using namespace std;
int main( )
char arr[2][4];
strcpy(arr[0],"you");
strcpy(arr[1],"me");
arr[0][3]=’&’;
cout<<arr[0]<<end1;
return 0;
执行后的输出结果是( )。
A. you&me
B. you
C. me
D. err