第1题:
有如下类声明: class XA{ int X; public: XA(int n){x=n;} }; class XB:public XA{ int y; public: XB(int a,int b); }; 在构造函数XB的下列定义中,正确的是( )。
A.XB::XB(inta,int b):x(a),y(b){}
B.XB::XB(int a,int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b){}
D.XB::XB(int a,int b):XA(a),XB(b){}
第2题:
若要产生一个4行30列的多行文本域,以下方法中,正确的是:
A、Inputtype=”text”Rows=”4”Cols=”30”Name=”txtintrol”
B、TextAreaRows=”4”Cols=”30”Name=”txtintro”
C、TextAreaRows=”4”Cols=”30”Name=”txtintro”/TextArea
D、TextAreaRows=”30”Cols=”4”Name=”txtintro”/TextArea
第3题:
阅读下列说明和C++程序,将应填入(n)处的字句写在对应栏内。
【程序1说明】
程序1中定义了数组的类模板,该模板使得对于任意类型的二维数组,可以在访问数组元素的同时,对行下标和列下标进行越界判断,并给出相应的提示信息(C++语言本身不提供对下标越界的判断)。
【程序1】
include < iostream. h >
template < class T > class Array2D;
template < class T > class Array2DBody {
friend (1);
T * tempBody;
int iRows, iColumns, iCurrentRow;
Array2DBody(int Rows,int Cols) {
tempBody =(2);
iRows = Rows;
iColumns = Cols;
iCurrentRow = -1;
}
public:
T& operator[ ] (int j){
bool row_ error, column_ error;
row_ error = column_ error = false;
try {
if ( iCurrentRow < 0||iCurrentRow > = iRows)
row_ error = true;
if( j < 0||j > = iColumns)
column_error = true;
if( row_error = = true [ [ column_ error = = true)
(3);
}
catch(char) {
if (row_error = = true)
cerr < < "行下标越界"[" < < iCurrentRow < < "]";
if( colmnn_error = = true)
cerr< <"列下标越界[" < <j< <"]";
cout < < "\n";
}
return tempBody[ iCurrentRow * iColumns + j ];
}
~ Array2 DBody ( ) { delete [ ] tempBody; } }; template < class T > class Array2D {
Array2DBody < T > tBody;
public:
Array2DBody < T > & operalor[ ] (int i) {
tBody, iCurreutRow = i;
(4);
Array2D(int Rows,int Cols): (5) {} };
void main( )
{
Array2D <int> al ( 10,20 );
Array2D <double> a2(3,5);
int bl;
double b2;
b1=a1[-5][10];//有越界提示:行下标越界[-5]
b1=a1[10][15];//有越界提示:行下标越界[10]
b1=a1[1][4];//没有越界提示
b2=a2[2][6];//有越界提示:列下标越界[6]
b2=a2[10][20];//有越界提示:行下标越界[10]列下标越界[20]
b2=a2[1][4];//没有越界提示
}
第4题:
下面是类MyClass的定义,对定义中各种语句描述正确的是( )。
class MyClass { publiC: void MyClass(int a) //①
{ x=a; ) int func(int a,int b) //②
{ x=a; y=b; } int func(int a,int b,int c=0) //③
{ x=a; y=b; z=c; } static void resetValue() //④
{ x=0; } private: int X,y,Z; };
A.语句①是类MyClass的构造函数定义
B.语句②和语句③实现类成员函数的重载
C.语句④实现对类成员变量x的清零操作
D.语句①、②、③和④都不正确
第5题:
下面是类MyClass的定义,对定义中各语句描述正确的是( )。 class MyClass { private: int x,y, z; public: void MyClass(int A) { x=a; } //① int f(int a, int B) //② { x=a; y=b; } int f(int a,
A.语句①是类MyClass 的构造函数的定义
B.语句②和③实现类成员函数的重载
C.语句④实现对类成员变量x的更新操作
D.语句①、②、③和④都不正确
第6题:
有如下类声明: class XA { int x; public: XA(int n) {x=n;} }; class XB: public XA{ int y; public: XB(int a,int b); };在构造函数XB的下列定义中,正确的是______。
A.XB:: XB(int a, int b):x(a),y(b) { }
B.XB::XB(int a, int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b)i}
D.XB::XB(int a,int b):XA(a),XB(b){}
第7题:
下列带缺省值参数的函数说明中,正确的说明是 ______。
A.int Fun(int x, int y=2,int z=3);
B.int Fun(int x=1,int y,int z=3);
C.int Fun(int x, int y=2,iht z);
D.int Fun(int x=1,int y, int z=3);
第8题:
下列方法中哪个方法是Sprite类中用来设置对准点的方法:()
第9题:
构造方法String(char[],int,int)中,第二和第三个参数分别用来生成字符串的字符型数组的起始位置和长度
第10题:
类MyClass的构造方法MyClass(int x,int y)的目的是使MyClass的成员变量privateintx,privateinty的值分别等于方法参数表中所给的值int x,int y。请写出MyClass(int x,int y)的方法体(用两条语句):()
第11题:
setRefPixelPosition(int x,int y)
defineReferencePixel(int x,int y)
setVisible(boolean visible)
setPosition(int x,int y)
第12题:
第13题:
有如下类声明: class XA{ int X; public: XA(int n){x=n;} }; class XB:publicXA{ int y; public: XB(int a,int b); ); 在构造函数XB的下列定义中,正确的是( )。
A.XB::XB(int a,int b):x(a),y(b){}
B.XB::XB(int a,int b):XA(a),y(b){}
C.XB::XB(int a,int b):x(a),XB(b){}
D.XB::XB(int a,int b):XA(a),XB(b){}
第14题:
设int*p2=&x,*p1=a;p2=*b,则a和b的类型分别是______ 。
A.int*和int
B.int*和int**
C.int 和int*
D.int*和int*
第15题:
下列程序在构造函数和析构函数中申请和释放类的数据成员int * a,申请时使用形参b初始化a,请填空。
class A
{
public:
A(int b) ;
~A( ) ;
private:
int * a;
};
A: :A(int b)
{
______;
}
A: :~A( )
{
______;
}
第16题:
在C++语言中,若类C中定义了一个方法int (int a,int b),那么方法(1)不能与该方法同时存在于类C中。
A.int f(int x,int y)
B.int f(float a,int b)
C.float f(int x,float y)
D.int f(int x,float y)
第17题:
有一个类A,下列为其构造方法的声明,其中正确的是
A.void A(int x){…}
B.A(int x){…}
C.a(int x){…}
D.void a(int x){…}
第18题:
A.GridLayout()
B.GridLayout(int rows,int cols)
C.GridLayout(int rows,int cols,int hgap,int vgap)
第19题:
第20题:
有一个类Demo,对与其构造方法的正确声明是()
第21题:
下面哪一个是合法的数组声明和构造语句()
第22题:
对
错
第23题:
int[] ages = [100];
int ages = new int[100];
int[] ages = new int[100];
int() ages = new int(100);