void main() 
{B b[2]={B(10,11),B(12,13)}; for(int i=0;i<2;i++) b[i].show()__________ 
} 
  
五、程序分析题(本大题共4小题,每小题5分,共20分) 1. 给出下面程序输出结果。 
#include class a {public: 
a(int i=10){x=i;cout<<\int x; }; 
class b:public a {public: 
b(int i):A(i){x=i;cout<<\private: a A; int x; }; 
void main() {b B(5); } 
答案:a:10 a:5 b:5,10 
[解析]定义对象B,先调用基类构造函数,在b构造函数中使用的是A(i),注意大小写,不 是a(i),也就是说调用基类的构造函数时没有实参值,所以采用默认值;在初始化类成员A,即 A(i),i=5,所以输入为a:5;最后是b类的构造函数,x=5,来自基类x=10,输出b:5,10。 2. 运行程序,写出程序执行的结果。 #include class Location {public: int X,Y; 
void init(int initX,int initY); int GetX(); int GetY(); }; 
void Location::init (int initX,int initY) {X=initX; Y=initY; } 
int Location::GetX() {return X; } 
int Location::GetY() {return Y; } 
void display(Location& rL) 
{cout<void main() 
{Location A[5]={{5,5},{3,3},{1,1},{2,2},{4,4}}; Location *rA=A; A[3].init(7,3); rA->init(7,8); 
for (int i=0;i<5;i++) display(*(rA++)); }  
 
3. 给出下面程序输出结果。 
#include  
int a[8]={1,2,3,4,5,6,7}; void fun(int *pa,int n); void main() {int m=8; fun(a,m); 
cout<void fun(int *pa,int n) {for (int i=0;i28  
4. 给出下面程序输出结果。 
#include  class A {int *a; public: 
A(int x=0):a(new int(x)){} ~A() {delete a;} 
int getA() {return *a;} void setA(int x) {*a=x;} }; 
void main() {A x1,x2(3); A *p=&x2; 
(*p).setA(x2.getA()+5); x1.setA(10+x1.getA()); 
cout<108; 
六、程序设计题(本大题共1小题,共10分) 1. 已知交通工具类定义如下。 
要求:(1)实现这个类;(2)定义并实现一个小车类car,是它的公有派生类,小车本身的私有 属性有载人数,小车的函数有init(设置车轮数,重量和载人数),getpassenger(获取载人数 ),print(打印车轮数,重量和载人数)。 class vehicle 
{protected: 
int wheels;//车轮数 float weight;//重量 public: 
void init(int wheels,float weight); int get_wheels(); float get_weight(); void print(); }; 
void vehicle::init(int wheels,float weight) {this->wheels=wheels; this->weight=weight; cout<int vehicle::get_wheels() {return wheels; } 
float vehicle::get_weight() {return weight;} 
void vehicle::print() 
{cout<<\车轮数:\重量:\