A.1
B.7
C.6
D.4
第1题:
根据短文内容判断给出的语句是否正确,正确的写“T”,错误的写“F”。
Pedestrian Critically Injured in Westwood HitandRun Crash
A pedestrian was critically injured in a Westwood area car accident near the comer of Wilshire Boulevard and Veteran Avenue early morning on January 5, 2016.
The police said it involved a hitandrun driver. The car was dark and was last seen traveling east on Ashton Avenue from Veteran Avenue. The investigation is ongoing.
It appears that the driver struck and seriously injured the pedestrian, and left the victim lying in the roadway without even stopping to help or call emergency personnel. Outrageous! Leaving the scene of an injury or fatal crash is a serious crime under California law. California Vehicle Code 20001(a)states:“The driver of a vehicle involved in an accident resulting in injury to a person, other than himself or herself, or in the death of a person shall immediately stop the vehicle at the scene of the accident.”
We hope the driver in this case is arrested and brought to justice. If you have any information about the suspect or the vehicle, please visit the HitandRun Reward website at hitandrunreward.com to offer a useful tip and become qualified for a $1,000 reward.
( )21. A pedestrian was dead in the hitandrun case.
( )22. Leaving the scene of an injury or fatal crash is not a serious crime under California law.
( )23. The investigation is going on.
( )24. The driver was against the California Vehicle Code 20001.
( )25. Any information about hitand run cases provided via hitandrunreward.com can get $1,000 reward.
参考答案:21、F 22、F 23、T 24、T 25、T
第2题:
若已定义了类Vehicle,则下列派生类定义中,错误的是
A.class Car:Vehicle{/*类体略*/);
B.class Car:public Car{/*类体略*/);
C.class Car:public Vehicle{/*类体略*/);
D.class Car:virtual public Vehicle{/*类体略*/);
第3题:
A.car
B.7
C.1
D.2
第4题:
A.1
B.2
C.3
D.4
第5题:
阅读以下说明和C++代码,填充代码中的空缺,将解答填入答题纸的对应栏内。
【说明】
某应急交通控制系统(TraficControISy ,tem)在红灯时控制各类车辆(Vehicle)的通
行,其类图如图5-1所示,在紧急状态下应急车辆红灯时也可通行,其余车辆按正常规
则通行。
下面的C++代码实现以上设计,请完善其中的空缺。
include <typeinfo>
include <iostream>
using namespace std;
class Vehicle {/*抽象基类,车辆*/
public :
virtual void run () = 0;
};
class Emergency( /*抽象基类,可在红灯时通行的接口,函数均为纯虚函数*/
public:
(1)=0 //isEmergent()函数接口
(2)=0 //runRedLight()函数接口
};
class Car: public Vehicle {
public :
-car(){ }
void run () { /*代码略*/ }
};
Ciass Truck:public vehicie {
Public;
-Truck(){ }
Void run() { /*代码略*/}
};
Class policecar: (3) {
Private:
bool isEmergency;
public :
PoliceCar () : Car () , Emergency () { this=>isEmergency = false;
}
PoliceCar (bool b) : Car () , Emergency () { this=>isEmergency = b; }
~PoliceCar () { }
bool isEmergent () { ret irn (4) ; }
void runRedLight () { /*代码略*/ }
};
/*类Ambulance. FireEngine/*实现代码略*/
class TraficControISystem {/*交通控制类*/
private :
Vehicle*v[24]; int numVeh: cles./*在构造函数中设置初始值为0*/
public:
void control(){ //控制在紧急情况下应急车辆红灯通行,其他情况按常规通行
for (int i = 0; i<[numVehicles;++] {
Emergency*ev=dynamic_cast<Emergency*(v[i]);
if (ev !=0(5)-: runRedLight ( )
Else (6)-:run()
}
}
Void add(vehicle){v[numvehicles++]=vehicle;}
/*添加车辆*/
Void shutdown(){for (int i =0;i<numvehicles;i++){ deletev[i];} }
}
int main () {
TraficControlSystem* tcs =new TraficControlSystem;
tcs->add (new Car () );, t cs->add (new PoliceCar ()) ;
tcs->add (new Ambulance ()) ; tcs- >add (new Ambulance (true)) ;
tcs->add (new FireEngine (true)) ; -.cs->add (new FireEngine ()) ;
tcs->add (new Truck ()) ;
tcs->control () ; tcs->shul Down ( ) ;
delete tcs;
}
参考答案:(1)virtualboolisEmergent0
(2)ivirtualvoidrunRedLight0
(3)publicCar,publicEmergency
(4)ithis->isEmergency
(5)ev
(6)iv[i]
解析:
本题考查C++语言程序设计的能力,涉及类、对象、函数的定义和相关操作。要求
考生根据给出的案例和执行过程说明,认真阅读理清程序思路,然后完成题目。
根据题目描述,以交通控制系统(TraicControISystem)为背景,本题目中涉及的各
类车辆和是否应急状态下在红灯时的通行情况。根据说明进行设计,题目给出了类图(图
5-1类图所示)。
图中父类Vehicle代表交通工具,设计为抽象类,包含一个方法:run(),表示行驶
某一个具体的交通工具对象,行驶的方法由具体子类型完成,所以Vehicle的run()为一
个纯虚函数:
Virtualvoidrun()=0;
Car和Truck都继承自Vehicle的两个子类型,所以它们都继承了Vehicle的run()方
法,各自行驶方式有所不同,所以都覆盖了Vehicle的run()方法,并加以实现:
voidrun(){/*代码略*/)
Car的两个子类型PoliceCar和Ambulance都继承自Car,从而PoliceCar和Ambulance
也都继承了Car中的run()方法。Truck的子类:eireEngine也继承了Truck中的run()方法。
图中接口Emergency在C++中采用抽象基类的方法实现,其中约定红灯时通行的相
关接口函数为:isEmergent()和runRedLight(),均为纯虚函数,原型中=0表示纯虚函数,
实现由子类完成:
virtualboolisEmergent()=0;
virtualvoidrunRedLight()=0;
isEmergent0函数接口约定应急车辆返回自身紧急情况状态,用bool类型的
isEmergency表示:this->isEmergency,其值在紧急情况下为bool值true,非紧急情况下
为bool值false。runRedLight0函数接口约定应急车辆在红灯时如何通行(isEmergency
为true,则通行,isEmergency为false,和普通车辆一样通行)。Emergency的子类有
PoliceCar、Ambulance和FireEngine,所以在这三个类中都要实现Emergency中定义的
纯虚函数接口。
交通控制类TraficControISystem对运行的交通工具进行控制,所有交通工具用
Vehicle数组v表示;numVehicles表示交通工具数量;control函数进行控制在紧急情况
下应急车辆红灯通行,其他情况按常规通行;add()表示有车辆加入系统,shutDown()在系统关闭时清除每个对象数组元素:deletev[];。Vehicle的子类具体类型有Car、Truck、
PoliceCar、Ambulance和FireEngine,所以、[]数组中对象有这些类型的对象,加入V[]
时会自动向上转型成为Vehicle类型,而实现了Emergency接口的应急车辆有
runRedLight0函数,其他Car和Truck只有“n0函数。因此,用for循环对每个v[i],判
定是否是Emergency类型,即是否继承了Eriergency,调用时动态绑定每个数组元素的
实际类型,需要通过动态类型转换:
Emergency*ev=dynamic_cast<Emeraency*>(v[i]);
如果转换成功,说明是Emergency的子类,实现了runRedLight0,可以调用runRedLight0,
否则调用run():
If(ev!=0)ev_->runRedLigh'.();
Elsev[i]->run();
主控逻辑代码在maln函数中实现。初始化TraficControISystem,用tcs表示,调用
tcs的add()函数添加具体的交通工具,这里会自动向上转型成为Vehicle类型,调用control()
对各车辆进行控制,调用shutDown()系统关闭,使用完数组对象之后,需要用delete操
作进行释放对象,即deletetcs;
因此,空(l)和空(2)需要定义纯虚函数isEmergent()和runRedLight0,原型中
=0题目代码中已经给出,所以空(1)和空(2)分别为“virtualboolisEmergent()”和“virtual
voidrunRedLight()”;空(3)需要继承CarjFIEmergency,即“publicCar,publicEmergency”;
空(4)要返回应急车辆对象的状态,即“this->isEmergency”;空(5)处动态类型转换
成功的对象ev;空(6)处为普通车辆对象v[i]。
第6题:
29. When people travel on business(出差) ,they usually take _________ .
A. a train or a plane
B. a boat or a train
C.a car or a boat .
D.a plane or a car
第7题:
第8题:
第9题:
()is the volume for loading goods of the vehicle.
第10题:
By car.
By bus.
By ship.
By train.
第11题:
By train and by car.
Just by car.
On foot.
第12题:
the car manufacturers were concerned about the American economy.
the market’s performance was found to be the worst in 50 years.
the prices of fuel rose to a level which was last seen in the 1950s.
the fuel prices were so high and the economy was facing a depression.
第13题:
使用VC6打开考生文件夹下的工程test17_1,此工程包含一个源程序文件test17_1.唧,但该程序运行有问题,请改正程序中的错误,使程序的输出结果如下:
Vehicle message
Car message
Vehicle message
源程序文件test17_1.cpp 清单如下:
include <iostream.h>
class vehicle
{
int wheels;
float weight;
public:
/***************** found *****************/
void message(void){ cout<<"Vehicle message\n";}
};
class car:public vehicle
{
int passenger_load;
public:
/***************** found *****************/
void message (void){cout>>"Car message\n";}
};
class truck:public vehicle
{
int passenger_load;
float payload;
public:
int passengers(void){return passenger_load;}
};
void main()
{
vehicle * unicycle;
unicycle=new vehicle;
/***************** found *****************/
unicycle.message()
delete unicycle;
unicycle=new car;
unicycle->message();
delete unicycle;
unicycle=new truck;
unicycle->message();
delete unicycle;
}
第14题:
A.train
B.bus
C.car
D.ship
第15题:
A.3
B.7
C.6
D.4
第16题:
A.2
B.7
C.6
D.4
第17题:
阅读以下说明和Java代码,填充程序中的空缺,将解答填入答题纸的对应栏内。
【说明】
某应急交通控制系统(TraficControIS,stem)在红灯时控制各类车辆(Vehicle)的通
行,其类图如图6-1所示,在紧急状态下应急车辆在红灯时可通行,其余车辆按正常规
则通行。
下面的Java代码实现以上设计,请完善其中的空缺。
【Java代码】
abstract class Vehicle
public Vehicle () { }
abstract void run
};
interface Emergency {
(1) ;
(2) ;
}
class Car extends Vehicle {
public Car () { }
void run () { /*代码略*/ }
};
class Truck extends Vehicle {
public Truck () { }
void run () { /*代码略*/ }
class PoliceCar (3)
boolean isEmergency = false;
public PoliceCar () { }
public PoliceCar(boolean b) { this . isEmergency =b; }
public boolean isEmergent () { return (4); }
public void runRedLight () { /*代码略*/ }
}
/*类Ambulance. FireEngine实现代码略*/
public class TraficControISystem {/。交通控制类。/
private Vehicle[ ]V=new Vehiele [24];
int numVehicles;
public void control() {
for (int i=0; i<numVehicles; i++) {
if (v[i] instanceof Enu rgency&& ((Emergency)V [i])
isEmergent()) {
( 5 ) . runRedLigh&39;: ( ) ;
}else
(6).run( )
}
}
void add (Vehicle vehicle) { v[numVehicles++]=vehicle;)/*添加车辆*/
void shutDown()(/*代码略*/}
public static void main (Stri.ng [ ] args) {
TraficControlSystem tcs = new TraficControlSystem() ;
tcs . add (new Car () ;
tcs .add (new PoliceCar () ;
tcs .add (new Ambulance () ;
tcs . add (new Ambulance (true》 ;
tcs . add (new FireEngine ( true》 ;
tcs . add (new Truck () ;
tcs . add (new FireEngine ( ) ;
tcs . control () ;
tcs . shutDown () ;
}
}
第18题:
In order to cut down on the carbon emission,more people choose to travel______.
A.by electric car,bicycle or plane
B.by private car,bicycle or bus
C.by bus,electric car or plane
D.by bicycle. bus or electric car
第19题:
第20题:
第21题:
By car.
By train.
By plane.
By ship.
第22题:
She is knowledgeable about cars.
Her employer will pay for her vehicle.
She is planning to buy her first vehicle
Her current car is unreliable.
第23题:
0, 0,0
150, 60, 0
Compilation fails.
150, 150, 150
An exception is thrown at runtime.