请使用VCAi或使用【答题】菜单打开考生文件夹proj2下的工程proj2。其中有类Point(“点”)、lleetangle(“矩形”)和Circle(“圆”)的定义。在程序所使用的平面坐标系统中,x轴的正方向是水平向右的,y轴的正方向是竖直向下的。请在

admin2016-06-12  18

问题 请使用VCAi或使用【答题】菜单打开考生文件夹proj2下的工程proj2。其中有类Point(“点”)、lleetangle(“矩形”)和Circle(“圆”)的定义。在程序所使用的平面坐标系统中,x轴的正方向是水平向右的,y轴的正方向是竖直向下的。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应该是:
  一一圆形…………
  圆心=(3,2)
  半径=1
  面积=3.14159
  一一外切矩形一一
  左上角=(2,1)
  右下角=(4,3)
  面积  =4
  注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//**********found**********”。
#include
#include
using rlal’tlespace st:d;
//平面坐标中的点
//本题坐标系统中,x轴的正方向水平向右,y轴的正方向竖直向下。
ClaSs Point:{
public:
  Point:(doubl e x=0.0,double y=0.
0):X一(x),y一(y){}
  double getX()const{return xj}
  double geY()const{return y一;)
  void set;X(double X){x  =x;)
  void setY(double y){y一。y;)
private:
  double x;  //x坐标
  double y;  //y坐标
};
//矩形
class Rectangl e{
public:
  Rectangle(Point P,int W,int h)
:point(p),width(w),height(h)
  {}
  dopble area()const.//矩形面积
  {
return width*height;
}
Point topLeft()const//左上角顶点
{
return point;
}
Point bottomRight()const
//右下角颂点(注:y轴正方向竖直向下),
{
  //**********found**********
return Point(_________);
}
private:
  Point point;//左上角顶点
  double width;//水平边长度
  double height;//垂直边长度
  };
  //圆形
  class Circle{
  public:
  Circle(Point P,double r):center
(p),radius(r){}
Rectangle boundingB0x()const,
//外切矩形
  double area()const//圆形面积
  {
  //********** found***********
  return PI*__________;
}
public:
  static const double PI;//圆周率
private:
  Point center;  //圆心
  double radius;  //半径
  };
  const double Circle::PI=3.14159;
  RectangleCircle::boundingBox
  ()const
  {
  //**********found***********
Point pt(_________);
int W,h;//**********found**********
W=h=__________;
return Rectangle(pt,W,h);
  }
  }
  int main()
  {
  Point P(3,2);
  Circle C(p,1);
  cout<<“--圆形一一\n”;
  cout<<--圆心= (“<cout<<“半径=”<<1<cout<<“面积;”<Rectangle bb=C.boundingBox();
Point tl=bb.topLeft();
Point br=bb.bottomRight();
cout<<”一一夕}、切矩形一一…一\n”;
cout<<“左上角=(”<  <<‘,’<cout<<“右下角=(”<  <<‘,’<  cout<<“面积=“t<endl;
  return 0;
}

选项

答案(1)l~oint.getX()+width,point.getY()+height (2)radius*:radius (3一)center.getX()一radius,center.getY。()一radius (4)2*radius

解析 本题考查Point类、Rectangle类和Circle类,其中涉及构造函数、const函数和静态成员。
【解题思路】
(1)主要考查考生对成员函数的掌握,程序要求返回右下角顶点,该点的x坐标为左上角顶点的x坐标加上width,该点的y坐标为左上角顶点y坐标加上height,即retum Point(point.getX()+width,point.getY()+height);。
(2)主要考查考生对成员函数的掌握,程序要求计算圆形面积,也就是返回圆面积,即return P1*radius*radius;。
(3)主要考查考生对成员函数的掌握,首先看函数声明:Rectangle Circle::boundingBox()const,可知该函数要返回的是一个Rectangle类型,即要返回的是圆的外切矩形。再看Rectangle类的构造函数Rectangle(Point p,int w,int h),由此可知,空格处要定义的点pt为左上角点,即Point pt(cen-ter.getX()一radius,center.getY()一radius);。
(4)由函数声明和Rectangle类的构造函数可知,w和h应该为直径,即w=h=2*radius;。
转载请注明原文地址:https://jikaoti.com/ti/SjE0FFFM
0

最新回复(0)