更多"[程序] #include class A{ public: "的相关试题:
[填空题]
[程序]
#include
#include
class B{
public:
B(char *s){name=new char[strlen(s)+1];strcpy(name,s);}
virtual void print( ){cout<<"姓名;"<
protected:
char *name;
};
class P1:public B{
public:
P1(char *s,float g):B(s){x=g;}
void print(int i)
{ cout<<"姓名:"<年薪:"<万元。 /n";}
private:
float x;
};
class P2:public B{
public:
P2(char *s,int n):B(s){ num=n;}
void print( ){cout<<"姓名;"<月工资:"<元。/n";}
private:
int num;
};
void main(void)
{
B *p;
B x("张明");
P1 y("王虎",4.2);
P2 z("李建国",5000);
p=&x;p->print( );
p=&y;p->print( );
y.print(1);
p=&z;p->print( );
}
执行以上程序后输出的第二行是() ,第四行是()。
[单项选择]下列程序的输出结果是()
#include
class Myclass
public:Myclass(int i=0,intj=0)
x=i;
y=j;
void show( ) cout < < "x=" < < x < < " " < "y=" < < y < < end1;
void show( )const cout < < "x=" < < " " < < "y=' < < y < < end1;
privated:
int x; int y;
;
void main( )
Myclass my1(3,4);
const my2(7,8);
my1.show( );my2.show( );
A. x=4,y=3;x=7,y=8
B. x=3,y=4;x=7,y=8
C. x=7,y=8;x=4,y=3
D. x=8,y=7;x=7,y=8
[单项选择]下列程序的输出结果是 #include class Myclass {
public:Myclass(int i=0,intj=0) { x=i;
y=j; } void show( ) { cout < < "x=" < < x
< < " " < "y=" < < y < < end1;} void show( )const { cout < < "x=" <
< " " < < "y=’ < < y < < end1;} privated:
int x; int y; }; void main(
) { Myclass my1(3,4); const my2(7,8);
my1.show( );my2.show( );}
A. x=4,y=3;x=7,y=8
B. x=3,y=4;x=7,y=8
C. x=7,y=8;x=4,y=3
D. x=8,y=7;x=7,y=8
[单项选择]下列程序执行结果是
#include <iostream.h>
class A
public:
int a;
A( ):a(10)cout<<a<<endl;
;
void main( )
A obj1;
A obj2(obj1);
cout<<" "<<obj2.a<<endl;
A. 10 10
B. 编译错误缺少拷贝构造函数
C. 10随机数
D. 随机数随机数
[单项选择]设有如下程序:
#include <iostream.h>
class A
public:
int i;
display( )
cout<<"class A/n";
;
class B
public:
int i;
display( )
cout<<"class B/n";
;
class C:public:A, public:B
int j;
public:
int i;
show( )
j=i*i;display( );
;
void main( )
C demo;
demo.show( );
则主程序运行时,将( )。
A. 因为变量i的重复定义而报错
B. 因为对象demo间接调用display函数时产生歧义性而报错
C. 因为类定义的语法错误而不能运行
D. 没有语法错误,能够正常输出结果
[单项选择]设有以下定义和程序: #include<iostream.h> class A1 { public: void show1( ) { cout<<"class A1"<<endl; } }; class A2:public A1 { public: void show2( ) { cout<<"class A2"<<endl; } }; class A3:protected A2 { public: void show3( ) { cout<<"class A1"<<endl; } }; void main( ) { A1 obj1; A2 obj2; A3 obi3; } 则以下不合语法的调用语句是( )。
A. objshow1();
B. obj2.show1();
C. obj3.show1();
D. obj2.show2();
[填空题]
执行下列代码
int b=100;
cout<<”Oct:”< 程序的输出结果是_________。
[填空题]
执行下列代码
double pi=3.141592;
cout 程序的输出结果是_________。
[填空题]#include<iostream.h>
class Bas
public:
~Bas( )cout<<"Bas construct"<<endl;
virtual void f( )=0;
;
class Dev:public Bas
public:
~Dev( )cout<<"Bas construct"<<endl;
virtual void f( )cout<<"Dev::f"<<endl;
;
void main( )
Bas*a=new Bas( );
Dev p;
a=&p;
a->f( );
[简答题]#include<iostream.h>
class A
public:
A(int i=8):y(i)
static int x:
int y;
;
int x=20;//对类成员初始化
void main( )
A a;
cout<<a.x<<","<<a.y<<endl;
[单项选择]
有如下程序:
#include
using namespace std;
public:
AA( ){ cout<<’1’; }
};
class BB: public AA{
int k;
public:
BB( ):k(0){ cout<<’2’; }
BB(int n):k(n){ cout<<’3’;}
}
int main( ){
BB b(4), c;
return 0;
}
运行时的输出结果是
A. 1312
B. 132
C. 32
D. 1412
[填空题]根据程序中的注释将下列缺失部分补充完整。
class A{
char*a;
public:
A():a(0){}
A(char *aa){//把aa所指字符串复制给a所指向的存储空间
a=__【11】__char[strlen(aa)+1];
strcpy(a,aa);
}
~A(){delete[]a;}
};
[单项选择]有如下类定义
class Test{
char a; const char b;
public:Test(char c){a=c;b=c;} //第1行
void f(char a)const{this->a=a;} //第2行
void g(char b){this->b=b;} //第3行
char h( )const{return a;} //第4行
};
编译时没有错误的行是
A. 第1行
B. 第2行
C. 第3行
D. 第4行
[单项选择]有如下类定义:
class A
char *a;
public:
A. )。 Dew char[strlen(aa)+1]
B. char[strlen(aa)+1]
C. char[strlen(aa)]D) Dew char[sizeof(aa)-1]
[单项选择]有以下程序:
#include <stdio.h>
char fun(char x,char y)
if(x<y) return x;
return y;
main( )
int a='9',b='8',c='7';
printf("%c/n",fun(fun(a,b),fun(b,c)));
程序的执行结果是( )。
A. 函数调用出错
B. 8
C. 9
D. 7
[填空题]以下程序的执行结果是______.
#include<<iostream.h>
c1ass A
public:
virtual void funl ( ) cout<<"A fun1"<<endl;
virtual void fun2 ( ) cout<<"A fun2"<<endl;
void fun3 ( ) cout<<" A fun 3 "<<endl:)
void fun4 ( ) cout<<" A fun4 "<<endl:
;
class B: public
public:
virtual void funl( ) cout<<" B funl"<<end1;
virtual void fun2 (int x) Cout<<"B fun2 "<<endl;
virtual void fun3( ) cout<<"B fun 3"<<endl;
void fun4( ) cout<<"B fun4"<<endl;
;
void main( )
A*p;
B b;
P=&b;
P->funl ( );
P->fun2( );
P->fun3( );
P->fun4( ):
[填空题]
补充完整下面的类定义:
class XCH{
char*a;
public:
XCH(char*aa){ //构造函数
a=new char[strlen(aa)+1];
strcpy(a,aa);
}
XCH& operator=(const XCH& x){ //重载赋值函数
delete[]a;
a=new char[strlen(x,a)+1];
strcpy(a,x,a);
______;
}
~XCH( ){delete[]a;)
}
[单项选择]有以下程序:
char fun(char x,char y)
if(x<y) return x;
return y;
void main( )
int a='9',b='8',c='7';
printf("%c/n",fun(fun(a,b),fun(b,c)));
程序的执行结果是( )。
A. 函数调用出错
B. 8
C. 9
D. 7
[单项选择]
有以下程序:
# include
void f(char *s, char *t)
{ char k; k=*s; *s=*t; *t=k; }
main( )
{ char str[10]="abcdefg", *p
p=str+strlen(str)/2+1;
f(p, p-2); printf("%s/n",str); }
程序运行后的输出结果是()。
A. abcdefg
B. gfedcba
C. gbcdefa
D. abedcfg