int index = 1; int [] foo = new int [3]; int bar = foo [index]; int baz = bar + index; What is the result?()
第1题:
请写出如下程序的输出结果:
#include
int a[]={2,4,6,8,10};
int &index(int i)
{ return a[i];
}
void main()
{
int i;
index(3)=12;
for (i=0;i<=4;i++)
cout<
答案:2 4 6 12 10
解析:
int &index(int i) 函数返回的是 a[i] 的引用,在main函数中修改了a[3]=12,故最终数组a的结果如答案所示。
第2题:
A.Bazhasthevalueof0
B.Bazhasthevalueof1
C.Bazhasthevalueof2
D.Anexceptionisthrown.
E.Thecodewillnotcompile.
第3题:
下面程序执行后,baz的值应是______。 public class Test9 { public static void main(String[] args) { int index = 1; int fox[] = new int [3]; iht bar = fox [index]; int baz = bar + index; System.out.println(baz); } }
A.0
B.1
C.2
D.编译错误
第4题:
关于以下初始化序列的执行结果的说法正确的是( )。 int index=1; int[] foo=new int[3]; int bar=foo[index]; int baz=bar+index;
A.baz的值为0
B.baz的值为1
C.编译通过,但产生异常
D.编译不能通过
第5题:
试题五(共 15 分)
阅读下列说明、图和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。
[说明]
已知对某载客车辆(Car)进行类建模,如图 5-1所示,其中类 Engine 表示发动机引擎,类 Wheel 表示车轮,类 Body 表示车身,类 Driver 表示司机,类 Passenger 表示乘客。

[C++代码]
const int (1) = 7; //定义最多载客数
const int MAX_WHEELS = 5; //定义最多轮胎数
class Body{ //此处代码省略 }; //车身类
class Passenger{ //此处代码省略 }; //乘客类
class Wheel{ //此处代码省略 }; //车轮类
class Driver{ //司机类
public:
string name; //表示第几路公交车司机
Driver(string driverName):name( (2) ){}; //构造函数
};
class Engine{ //引擎类
public:
string engineNo; //引擎编号
Engine(string engineNo){ (3) ->engineNo = engineNo; } //构造函数
};
class Car{ //汽车类
protected:
Engine * engine; Driver * driver; Body body;
Wheel * wheels[MAX_WHEELS]; Passenger * passengers[MAX_PASSENGERS];
public:
Car(Driver *driver){ //构造函数
this->driver = driver;
engine = new Engine("TX6536 型号引擎");
for (int index = 0; index < MAX_WHEELS; index++){
wheels[index] = new Wheel();
}
for (int index = 0; index < MAX_PASSENGERS; index++){
passengers[index] = NULL;
}
}
virtual ~Car(){ //析构函数
for (int index=0; index < MAX_WHEELS; index++)
delete wheels[index];
delete (4) ;
}
int getPassengerNumber(){ //获取车上乘客数量
//此处代码省略
}
void getOnPassenger(Passenger * aPassenger ){ //乘客上车
//此处代码省略
}
void run(){ //开车
if(driver == NULL){ cout << "司机尚未上车!"; return; }
//此处代码省略
}
};
void main(){
Driver driver("第五路公交车司机");
Car car( (5) );
Passenger passengers[MAX_PASSENGERS];
for (int index = 0 ; index < MAX_PASSENGERS; index ++) //乘客上车处理
car.getOnPassenger(&passengers[index]);
car.run();
}

第6题:
Table TAB1 was created using the following statement: CREATE TABLE tab1 (c1 INT, c2 INT, c3 INT, c4 INT, c5 INT); If column C1 is unique and queries typically access columns C1 and C2 together, which statement(s) will create index(es) that will provide optimal query performance? ()
第7题:
charAt(int index)表示从字符串中取得一个字符,该字符的位置是index
第8题:
int index = 1; int foo = new int ; int bar = foo [index]; int baz = bar + index; What is the result?()
第9题:
<
=
<=
>=
第10题:
Baz has the value of 0
Baz has the value of 1
Baz has the value of 2
An exception is thrown.
The code will not compile.
第11题:
CREATE UNIQUE INDEX xtab1 ON tab1 (c1); CREATE INDEX xtab2 ON tab1 (c2) INCLUDE (c3)
CREATE UNIQUE INDEX xtab1 ON tab1 (c1) INCLUDE (c2, c3)
CREATE UNIQUE INDEX xtab1 ON tab1 (c3, c2, c1)
CREATE UNIQUE INDEX xtab1 ON tab1 (c2) INCLUDE (c1, c3)
第12题:
Foo has the value “”
Foo has the value null
An exception is thrown
The code will not compile
第13题:
下面函数的作用是【 】。
int index(int x,int a[],int n)
{
for(int i=0;i<n;i++)
{
if(a[i]==x)
return i;
}
return i;
}
第14题:
请完成Java程序:本题是一个冒泡排序程序的实例。冒泡排序的含义是将相邻的两个数作比较,如果是升序排列的话,如果前边的数大,则将两个数交换。从第一个数开始两两比较一次,就可以将最大的数移动到最后。
注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。
import java.io.*;
public class simple
{
public static int[]Data=new int[10];
public static void main(String[] args)
int i;
int Index;
Index=0;
InputStreamReader ir;
BufferedReader in;
ir=new InputStreamReader(System.in);
in=new BufferedReader(ir);
try
{
do
{
System.out.println("Please input the number"+
Index+"you want to sort(Exit for 0):");
String s=in.readLine();
Data[Index]=Integer.parseInt(s);
Index++;
}
while(Data[Index-1]!=0);
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
System.out.print("Before bubble sorting:");
for(i=0; i<Index-1; i++)
System.out.print(" "+Data[i]+" ");
System.out.println(" ");
BubbleSort(Index-1);
System.out.print("After Bubble Sorting:");
for(i=0; i<Index-1;i++)
System.out.print(" "+Data[i]+" ");
System.out.println(" ");
}
public static void BubbleSort(int Index)
{
int i, j, k;
boolean Change;
int Temp;
for(j=Index; j>1;j--)
{
Change=false;
for(i=0; i<j-1;i++)
{
if(Data[i+1]<Data[i])
{
Temp=Data[i+1];
Data[i+1]=Data[i];
______;
______;
}
}
if(Change)
{
System.out.print("Current Sorting Result:");
for(k=0; k<Index; k++)
System.out.print(" "+Data[k]+" ");
System.out.println(" ");
}
}
}
}
第15题:
阅读下列说明、图和C++代码,填补空缺。
[说明]
已知对某载客车辆(Car)进行类建模,如图12-2所示,其中类Engine表示发动机引擎,类Wheel表示车轮,类Body表示车身,类Driver表示司机,类Passenger表示乘客。

const int __________ =7; //定义最多载客数
const int MAX_WHEELS=5; //定义最多轮胎数
class Body{ //此处代码省略 ); //车身类
class Passenger{ //此处代码省略}; //乘客类
Class Wheel{ //此处代码省略}; //车轮类
Class Driver{ //司机类
public:
string name; //表示第几路公交车司机
Driver(string driverName):marne( __________ ){}; //构造函数
};
class Engine{ //引擎类
public:
string engineNo; //引擎编号
Engine(string engineNo){ __________ ->engineNo=engineNo; }
//构造函数
};
Class Car{ //汽车类
protected:
Engine *engine; Driver *driver; Body body;
Wheel *wheels[MAX_WHEELS]; Passenger *passengers[MAX_PASSENGERS];
public:
Car(Driver *driver)( //构造函数
this->driver=driver;
engine=new Engine("TX653 6型号引擎");
for(int index=0; index<MAX_WHEELS; index++){
wheels[index]=new Wheel( );
}
for(int index=0; index passengers[index]=NULL;
}
}
virtual -Car( ){ //析构函数
for (int index=0; index<MAX_WHEELS; index++)
delete wheels[index];
delete __________ ;
}
int getPassengerNumber( ){ //获取车上乘客数量
//此处代码省略
}
void getonpassenger(Passenger *apassenger ){
//乘客上车
//此处代码省略
}
void run( ){ //开车
if(driver==NULL){cout<< "司机尚未上车!"; return; }
//此处代码省略
}
};
void main( ){
Driver driver("第五路公交车司机");
Car car( __________ );
Passenger passengers[MAX_PASSENGERS];
for(int index=0; index<MAX_PASSENGERS; index++)
//乘客上车处理
car. getOnPasSenger(&passengers[index]);
car. run( );
}
第16题:
下列程序执行后,baz的值应是 int index=1; int fox[ ]=new int[3]; Int bar=fox[index]; int baz:bar+index;
A.0
B.1
C.2
D.编译错误
第17题:
int index = 1; String test = new String; String foo = test[index]; What is the result?()
第18题:
StringBuffer deleteCharAt(int index)表示删除索引index-1处的字符
第19题:
int index = 1; boolean test = new Boolean; boolean foo= test [index]; What is the result?()
第20题:
int index = 1; String [] test = new String[3]; String foo = test[index]; What is the result?()
第21题:
Baz has the value of 0
Baz has the value of 1
Baz has the value of 2
An exception is thrown.
The code will not compile.
第22题:
Foo has the value of 0.
Foo has the value of null.
Foo has the value of true.
Foo has the value of false.
An exception is thrown.
The code will not compile.
第23题:
对
错
第24题:
Foo has the value “”
Foo has the value null
An exception is thrown
The code will not compile