全国2006年10月高等教育自学考试
protected:
int a;
public:
void setOne(int x){a=x;}
void showOne(){cout<<"a="<<a<<endl;}
};
class Two:private One{
public:
void setT wo(int x){a=x;}
};
void main()
{ T wo obj;
obj.setTwo(10);
cout<<"obj.a="<<obj.a<<endl;
}
24.下面程序实现输出半径为2.5的圆的面积,但输出结果是0,找出原因并提出修改意见。
class point{
private: float x,y;
public: float area( ){return 0.0;}
};
const float pi=3.14159f;
class circle:public point{
private: float radius;
public: void setRadius(float r){radius=r;}
float area(){return pi*radius*radius;}
};
void main()
{ point *p;
circle c;
c.setRadius(2.5);
p=&c;
cout<<"The area of circle is"<<p->area()<<endl;
}
25.下面程序中有一处错误,请用下横线标出错误所在行并说明出错原因。
class A{
int x;
friend class B;
};
class B{};
class C: public B{
void func(A *p);
};
void C::func(A *p)
{ p->x--; }
四、完成程序题(本大题共5小题,每小题4分,共20分)
26.为使下列程序输出结果为:
Y=1,Y=3,Z=5
请在横线处填上适当的字句,以使程序完整。
════════════════════════════════════════════════════════════════════
- 本套试题共分8页,当前页是第3页-