void main()
{B b[2]={B(10,11),B(12,13)}; for(int i=0;i<2;i++) __________ }
五、程序分析题(本大题共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); }
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;i4. 给出下面程序输出结果。 #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<六、程序设计题(本大题共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<<\车轮数:\重量:\