niusouti.com

程序设计题(每题15分,共30分) 1.写圆类(Circle)具有一下属性和功能 (1)具有属性:半径radius(3分); (2)写两个构造方法Circle(); (3分) Circle(double radius);(3分) (3)写两个方法求圆周长get Circumference ();(3分)面积getArea();(3分)

题目

程序设计题(每题15分,共30分) 1.写圆类(Circle)具有一下属性和功能 (1)具有属性:半径radius(3分); (2)写两个构造方法Circle(); (3分) Circle(double radius);(3分) (3)写两个方法求圆周长get Circumference ();(3分)面积getArea();(3分)


相似考题

2.阅读下列Java程序和程序说明,将应填入(n)处的字句写在对应栏内。【说明】下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toString方法输出中心点的值。在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。public class Point{private double xCoordinate;private double yCoordinate;public Point 0 }public Point(ouble x, double y){xCoordinate = x;yCoordinate = y;}public String toString(){return "( + Double.toString(Coordinate)+ ","+ Double.toString(Coordinate) + ");}//other methods}public class Ball{(1); //中心点private double radius; //半径private String colour; ///颜色public Ball() { }public Ball(double xValue, double yValue, double r)// 具有中心点及半径的构造方法{center=(2);//调用类Point 中的构造方法radius = r;}public Ball(double xValue, double yValue, double r, String c)// 具有中心点、半径及颜色的构造方法{(3);//调用3个参数的构造方法colour = c;}public String toString(){return "A ball with center" + center, toString() + ", radius"+ Double.toString(radius) + ", colour" + colour;}//other methods}public class MovingBall. (4){private double speed;public MovingBall() { }public MovingBall(double xValue, double yValue, double r, String e, double s){(5);// 调用父类Ball中具有4个参数的构造方法speed = s;}public String toString( ){ return super, toString( ) + ", speed "+ Double.toString(speed); }//other methods}public class Tester{public static void main(String args[]){MovingBall mb = new MovingBall(10,20,40,"green",25);System.out.println(mb);}}

3.使用VC6打开考生文件夹下的工程test7_3,此工程包含一个源程序文件test7_3.cpp,其中含有一个类Circle的定义,但该类的定义并不完整。请按要求完成下列操作,将类Circle的定义补充完整。(1)为类Circle增加一个构造函数,该函数有一个参数,并在构造时将该参数值赋给成员radius。将该函数实现为一个非内联函数,并且使用参数列表的方式将类成员赋值。请在注释“//**1**”之后添加适当的语句。(2)为类Circle增加一个成员函数print(),使得可以输出有关圆的信息,比如下列程序Circle c;c.SetRadius(5);c.Print();将输出:The circle has radius of 5!请在注释“//**2**”之后添加适当的语句。(3)完成友元函数void CompareR(Circle *cl,Circle*c2)的定义,在屏幕中输出c1与c2比较radius大小结果,要求使用 if-else结构完成。请在注释“//**3**”之后添加适当的语句。输出结果如下;The circle has radus of 5!The circle has radius of 10!c1<c2注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。源程序文件test7_3.cpp清单如下:include<iostream.h>class Circle{public:Circle():radius(5){}//**1**void SetRadius(int r) {radius=r; }int GetRadius() {return radius; }//**2**friend void CompareR(Circle *c1,Circle*C2);private:int radius;};void CompareR(Circle *c1,Circle *C2){//**3**cout<<"c1>c2"<<endl;elseif((c1->GetRadius())==(c2->GetRadius()))cout<<"c1=c2"<<endl;elseif((c1->GetRadius())<(c2->GetRadius()))cout<<"c1<c2"<<endl;}void main(){Circle c1;c1.SetRadius(5);C1.Print();Circle c2(10);c2.Print();CompareR(&c1,&c2);}

更多“程序设计题(每题15分,共30分) 1.写圆类(Circle)具有一下属性和功能 (1)具有属性:半径radius(3分); (2)写两个构造方法Circle(); (3分) Circle(double radius);(3分) (3)写两个方法求圆周长get Circumference ();(3分)面积getArea();(3分)”相关问题
  • 第1题:

    ●试题六

    阅读下列程序说明和C++代码,将应填入(n)处的字句写在答卷的对应栏内。

    【说明】

    源程序中定义了Circle类与Money类,Circle类可对半径为r的圆进行周长与面积的计算,而Money类用于计算一圆形游泳池的造价。游泳池四周有原形过道,过道外围上栅栏,过道宽度为3米,根据键入的游泳池半径,每米栅栏价格及每平方米过道价格,即可计算出游泳池的造价。请按要求完成下列操作,将程序补充完整。

    ①定义符号常量PI(值为3.14159f)与WIDTH(值为3.00f),分别用于表示圆周率与过道的固定宽度。

    ②定义Circle类默认构造函数,把私有成员radius初始化为参数r的值。

    ③完成Money类默认构造函数的定义,把私有成员FencePrice(每米栅栏的价格)、 ConcretePrice(每平方米过道的价格)初始化为参数f,c的值。

    ④完成Money类成员函数float Money::TotalMoney(float fencelen, float conarea)的定义,根据参数fencelen(栅栏的长度)和conarea(过道的面积),返回栅栏与过道的总造价。

    注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。

    源程序文件test4.cpp清单如下:

    #include <iostream.h>

    (1)

    class Circle

    {

    private:

    float radius;

    public:

    (2)

    float Circumference(){return 2 * PI * radius;}

    float Area(){return PI * radius * radius;}

    };

    class Money

    {

    private:

    float FencePrice;

    float ConcretePrice;

    public:

    Money(float f,float c);

    float TotalMoney(float fencelen, float conarea);

    };

    Money::Money(float f,float c)

    {

    (3)

    }

    float Money::TotalMoney(float fencelen, float conarea)

    {

    (4)

    }

    void main()

    {

    float radius,fence,concrete;

    cout.setf(ios::fixed);

    cout.setf(ios::showpoint);

    cout.precision (2) ;

    cout << "Enter the radius of the pool: ";

    cin >> radius;

    cout << "Enter the FencePrice: ";

    cin >> fence;

    cout << "Enter the ConcretePrice: ";

    cin >> concrete;

    Circle Pool(radius);

    Circle PoolRim(radius + WIDTH);

    Money mon(fence,concrete);

    float totalmoney=mon.TotalMoney(PoolRim.Circumference(),(PoolRim.Area() - Pool.Area()));

    cout << "The total money is RMB " << totalmoney << endl;

    }


    正确答案:

    ●试题六

    【答案】(1const float PI = 3.14159f;

    const float WIDTH =3.00f;

    2Circle(float r):radius(r){};

    3FencePrice=f;

    ConcretePrice=c;

    4return FencePrice*fencelen+ConcretePrice*conarea;

    【解析】本题考查了考生对符号常量的定义及类的定义与实现等方面的内容。注意常类型的定义应使用const关键字。

  • 第2题:

    下列( ) 是用来画圆、圆弧及椭圆的。

    A、Circle方法

    B、Pset方法

    C、Line属性

    D、Point属性


    正确答案:A

  • 第3题:

    请编写一个完整的Java Application程序,能够计算圆的周长和面积。

    要求:

    (1)定义点类CPoint;

    (2)定义圆类CCircle继承自类CPoint,类中属性包括:圆心,半径,类中方法包括:求周长perimeter()、求面积area();

    (3) 定义主类CCircleDemo,利用类CCircle输出一个圆的圆心,半径,周长和面积


    答案:如下

    解析:

    public class CPoint{

     private float radius;

     public CCircle(){

      this.radius=5.0f;

     }

     public CCircleDemo(float radius){

      this.radius=radius;

     }

     public void Area(){

      System.out.println("半径为"+this.radius+"面积是:"+(3.14*radius*radius));

     }

     public void perimeter(){

      System.out.println("半径为"+this.radius+"周长是:"+(3.14*2*radius));

    }


    public static void main(String arg[]){

     CCircle c1=new CCircle();

     c1.Area();

     c1.perimeter();

      CCircle c2=new CCirclet(9.0f);

     c2.Area();

     c2.perimeter();

    }

    }


  • 第4题:

    阅读以下说明和C代码,将应填入(n)处的字句写在的对应栏内。

    【说明】

    在一个简化的绘图程序中,支持的图形种类有点(point)和圆(circle),在设计过程中采用面向对象思想,认为所有的点和圆都是一种图形(shape),并定义了类型shape t、 point t和circle t分别表示基本图形、点和圆,并且点和圆具有基本图形的所有特征。

    【C代码】

    typedef enum { point,circle } shape type; /* 程序中的两种图形:点和圆 */

    typedef struct { /* 基本的图形类型 */

    shape_type type; /* 图形中类标识:点或者圆*/

    void (*destroy) (); /* 销毁图形操作的函数指针*/

    void (*draw) (); /* 绘制图形操作的函数指针*/

    } shape_t;

    typedef struct { shape_t common; int x; iht y; } point_t; /* 定义点类

    型, x, y为点坐标*/

    void destroyPoint (point_t* this) { free (this); printf ("Point destoryed!

    \n"); } ) /* 销毁点对象*/

    void drawPoint(point_t* this) { printf("P(%d,%d)", this->x, this->y); }

    /* 绘制点对象*/

    shape_t* createPoint (va_list* ap) (/* 创建点对象,并设置其属性*/

    point_t* p_point;

    if ( (p_point= (point_t*)malloc (sizeof (point_t)) ) ==NULL) returnNULL;

    p_point->common, type = point; p_point->common, destroy = destroyPoint;

    p_point->common.draw = drawPoint;

    p_point->x = va_arg(*ap, int); /* 设置点的横坐标*/

    p_point->y = va_arg(*ap, int); /* 设置点的纵坐标*/

    return (shape_t*)p_ooint; /*返回点对象指针*/

    }

    typedef struct { /*定义圆类型*/

    shape_t common;

    point_t 4center; /*圆心点*/

    int radius; /*圆半径*/

    } circle_t;

    void destroyCircle(circle_t* this){

    free((1)); free(this); printf("Circle destoryed!\n");

    }

    void drawCircle(circle_t* this) {

    print f ("C (");

    (2).draw(this->center); /*绘制圆心*/

    printf(",%d) ", this->radius);

    }

    shape_t* createCircle(va_list4 ap) { /*创建一个圆,并设置其属性*/

    circle_t4 p circle;

    if ((p_circle = (circle_t4)malloc (sizeof (circle_t)) ) ==NULL ) return NULL;

    p_circle->common.type = circle; p_circle->common.destroy = destroy

    Circle;

    p_circle->common.draw = drawCircle;

    (3) = createPoint(ap); /* 设置圆心*/

    p_circle->radius = va_arg(*ap, int); /* 设置圆半径*/

    return p_circle;

    }

    shape_t* createShape(shape_type st, "') { /* 创建某一种具体的图形*/

    va_list ap; /*可变参数列表*/

    &nbs


    正确答案:(1)this->center (2)this->center->common (3)p_circle->center (4)va start (5)C(P(2040)10)
    (1)this->center (2)this->center->common (3)p_circle->center (4)va start (5)C(P(20,40),10) 解析:本题考查C语言中指针机制、可变数目参数机制及结构体存储映像。本题中涉及的三个数据结构shape_t、circle_t和point_t的关系如下图所示。

    通过阅读给出的程序代码可以看出,point_t和circle_t两种结构通过其成员shape_t common表示了上图中的继承关系:circle t中的数据成员point_t*center表示了与 pornt_t之间的引用关系。
    函数destroyCircle(circle_t*this)完成一个circle t对象的内存释放工作。在结构circle t定义中,由于数据成员center是一个指针,所以必须释放对应内存,即free(this->center)。
    函数drawCircle(circle t* this)完成圆形的显示工作。其中需要显示其圆心的信息,而此信息由circle_t. common. draw()函数完成,即this->center->common.draw(this.center)。 point_t类型的显示工作由函数draw Point完成,其在屏幕上显示的信息格式为P(x,y),其中x表示点的横坐标,y表示点的纵坐标。圆形的显示函数drawCirele在屏幕卜显示的信息格式为C(P(x,y),r),其中x表示圆心的横坐标,y表示圆心的纵坐标,r表示半径。
    函数ereateCircle(va_list*叩)完成创建一个圆形工作,其中需要创建其圆心对象,a圆心对象的地址保存在circle t.center数据成员中。该函数的参数采用了C语言提供的标准类型va list,以处理可变数目的函数实参。对于可变数目的参数列表的一般处理方式如下:
    #includestdarg.h>
    void foo(char*fmt,…)/*表示fmt后面的参数个数可变*/
    {
    va listap;/*保存可变数目的参数列表*/
    va start(ap,fmt);/*初始化ap,保存参数fmt后面的实参列表*/
    //…
    va arg(ap,TYPE);/*获取下一个实参,其中TYPE指明该参数的类型*/
    //…
    va end(ap);/*释放ap占用的资源*/
    }

  • 第5题:

    使用VC6打开考生文什夹下的工程test1_3。此工程包含一个test1_3.cpp,其中定义了类circle和column,其中column类由circle类protected派生,但两个类的定义并不完整。请按要求完成下列操作,将程序补充完整。

    (1)定义类circle的保护数据成员r和area,它们都是double型的数据。请在注释“//**1**”之后添加适当的语句。

    (2)添加类circle的无参数的构造函数,使circle对象的r默认值为0,请在汁释“//**2**”之后添加适当的语句。

    (3)添加派生类column构造函数的定义,传入的参数为double型的height和radius,并将具分别赋值给数擗成员h和基类的r,请在注释“//**3**”之后添加适当的语句。

    (4)完成派生类column的成员函数print的定义,使其以格式“r=_area=_”先输出半径r和底面积area,再以格式“h=_vol=_”输出高h和体积vol的值,请在注释“//**4**”之后添加适当的语句。

    输山结果如下:

    r=1 area=3.1416

    h=2 vo1=6.2832

    注意:除在指定的位置添加语句外,请不要改动程序中的其他语句。

    源程序文件test1_3.cpp清单如下:

    include<iostream.h>

    const double pi=3.1416;

    class circle

    {

    protected:

    //**1**

    public:

    //**2**

    circle(double radius){ r=radius;}

    void print()

    {

    area=r*r*pi;

    cout<<"r="<<r<<" "<<"area="<<ared<<endl;

    }

    };

    class column: protected circle

    {

    protected:

    double h;

    public:

    //** 3 **

    void print()

    {

    // ** 4 **

    }

    };

    void main()

    {

    column col(1.0,2.0);

    Col.print();

    }


    正确答案:(1) doubler; double area; (2) circle(){r=0;} (3) column(double radiusdouble height):circle(radius){h=height;} (4) circle::print(); cout"h="h" ""vol="area *hendl;
    (1) doubler; double area; (2) circle(){r=0;} (3) column(double radius,double height):circle(radius){h=height;} (4) circle::print(); cout"h="h" ""vol="area *hendl; 解析:主要考查考生对于类的数据成员定义与成员函数构造的掌握,其中(3)使用了参数列表进行变量赋值,(4)使用作用域符::调用基类print函数。

  • 第6题:

    阅读以下函数说明和Java代码,将应填入(n)处的字句写在对应栏内。

    【说明】

    下面的程序先构造Point类,再顺序构造Ball类。由于在类Ball中不能直接存取类Point中的xCoordinate及yCoordinate属性值,Ball中的toString方法调用Point类中的toStrinS方法输出中心点的值。在MovingBsll类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值。

    【Java代码】

    //Point.java文件

    public class Point{

    private double xCoordinate;

    private double yCoordinate;

    public Point(){}

    public Point(double x,double y){

    xCoordinate=x;

    yCoordinate=y;

    }

    public String toStrthg(){

    return"("+Double.toString(xCoordinate)+","

    +Double.toString(yCoordinate)+")";

    }

    //other methods

    }

    //Ball.java文件

    public class Ball{

    private (1);//中心点

    private double radius;//半径

    private String color;//颜色

    public Ball(){}

    public Ball(double xValue, double yValue, double r){

    //具有中心点及其半径的构造方法

    center=(2);//调用类Point中的构造方法

    radius=r;

    }

    public Ball(double xValue, double yValue, double r, String c){

    //具有中心点、半径和颜色的构造方法

    (3);//调用3个参数的构造方法

    color=c;

    }

    public String toString(){

    return "A ball with center"+center.toString()

    +",radius "+Double.toString(radius)+",color"+color;

    }

    //other methods

    }

    class MovingBall (4) {

    private double speed;

    public MovingBall(){}

    public MoyingBall(double xValue, double yValue, double r, String c, double s){

    (5);//调用父类Ball中具有4个参数的构造方法

    speed=s;

    }

    public String toString(){

    return super.toString()+",speed"+Double.toString(speed);

    }

    //other methods

    }

    public class test{

    public static void main(String args[]){

    MovingBall mb=new MovingBall(10,20,40,"green",25);

    System.out.println(mb);

    }

    }


    正确答案:(1) Point center (2) new Point(xValueyValue) (3) this(xValueyValuer) (4) extends Ball (5) super(xValueyValuerc)
    (1) Point center (2) new Point(xValue,yValue) (3) this(xValue,yValue,r) (4) extends Ball (5) super(xValue,yValue,r,c) 解析:在类Ball的有参数构造函数中,对成员变量center通过调用Point类的构造方法初始化,而center在类Ball中尚未声明。结合注释可得空(1)是将center变量声明为Point对象引用,故空(1)应填Point。空(2)是调用Point类的构造函数,根据题意,此处应将xValue和yValue作为参数调用类Point的有参数构造函数,故空(2)应填new Point(xValue,yValue)。
    根据注释,空(3)是调用类Ball的有3个参数的构造方法,而其所在方法本身就是类Ball的一个构造方法,因此可用this来调用自身的构造方法,故空(3)应填this(xValue,yValue,r)。
    根据题述“在MovingBall类的toString方法中,super.toString调用父类Ball的toString方法输出类Ball中声明的属性值”,可知类MovingBall是类Ball的子类,因此空(4)应填extends Ball。
    根据注释,空(5)是调用父类Ball中具有4个参数的构造方法,通过super关键字实现,故空(5)应填super(xValue,yValue,r,c)。

  • 第7题:

    下列程序中,先声明一个圆类circle和一个桌子类table,另外声明一个圆桌类roundtable,它是由 circle和table两个类派生的,要求声明一个圆桌类对象,并输出圆桌的高度,面积和颜色。请填空完成程序

    include<iostream.h>

    include<string.h>

    class circle{

    double radius;

    public:

    circle(double r){radius=r;}

    double get_area(){return 3.416*radius*radius;}

    };

    class table{

    double height;

    public:

    table(double h)<height=h;}

    double get_height(){return height;}

    };

    class roundtable:public table,public circle{

    char *color;

    public:

    roundtable(double h,double r,char c[]): 【 】 {

    color=new char[strlen(c) +1];

    【 】;

    };

    char*get_color(){return color;}

    }:

    void main(){

    roundtable rt(0.8,1.0,“白色”);

    cout<<"圆桌的高:"<<rt. get_height()<<end1;

    cout<<"圆桌面积:"<<rt.get_area()<<end1;

    cout<<"圆桌颜色:"<<n.get color()<<end1;

    }


    正确答案:circle(r) table(h) strcpy(color c)
    circle(r), table(h) strcpy(color, c)

  • 第8题:

    根据程序中的注释将下列缺失部分补充完整。

    class Point{

    int x,y; //点的x和y坐标

    public:

    Point(int xx=0,int yy=0):x(xx),y(yy){}

    };

    class Circle{

    Point center;//圆心位置

    int radius; //半径

    public: //利用cx和cY分别初始化圆心的x和y坐标

    circle(int cx,int cy,int r): 【 】 ,radius(r){}

    void area()(cout<<3.14159*radius*radius<<end1;)

    };


    正确答案:center(cxcy)
    center(cx,cy) 解析:center在类Circle中声明为成员对象。成员对象的初始化工作是在成员初始化列表中完成的。初始化的一般格式如下:
    <类名>(<总形参表>):<成员对象1>(<形参表1>),<成员对象2>(<形参表2>),…
    {

    }

  • 第9题:

    当设置了容器对象的DrawWidth属性后,会影响()

    • A、Pset、Line、Circle方法
    • B、Line、Shape控件
    • C、Pset、Line、Circle方法和Line、Shape控件
    • D、Line、Circle、point方法

    正确答案:A

  • 第10题:

    单选题
    关于图3.19的叙述()是不正确的。
    A

    Rectangle类和Circle类都有名为area的属性,这两个属性一定是相同的属性

    B

    Rectangle类和Circle类都有名为getArea的操作,这两个操作一定是相同的操作

    C

    Rectangle中名为length的属性和Circle类中名为radius的属性,这两个属性一定是不同的属性

    D

    Shape类有一个属性,Circle类有两个属性,Rectangle类有三个属性


    正确答案: C
    解析: 在父类与子类的继承关系中,多态这种方法使得在多个子类中可以定义同一个操作或属性名,并在每个子类中可以有不同的实现。Rectangle和Circle都继承于父类Shape,对于Shape而言,会有getArea()的操作。但是子类Rectangle和Circle的getArea方法的实现可以完全不一样的,这就体现了多态的特征。至于选项D://Circle类和Rectangle类都要从Shape类继承一个属性,因此分别有"1+1=2"个属性和"2+1=3"个属性。

  • 第11题:

    单选题
    In the figure below, a small circle, with radius x, is inside a larger circle, with radius 6. What is the area, in terms of x, of the shaded region?
    A

    6π-2πx

    B

    6π-πx2

    C

    12π-2πx

    D

    36π-2πx

    E

    36π-πx2


    正确答案: E
    解析:
    根据图示可知,阴影部分的面积等于大圆的面积减去小圆的面积,即36π- x2π,因此选E。

  • 第12题:

    单选题
    Circles O and P intersect at exactly one point, as shown in the figure above. If the radius of circle O is 2 and the radius of circle P is 6, what is the circumference of any circle that has OP as a diameter?
    A

    B

    C

    12π

    D

    16π

    E

    64π


    正确答案: E
    解析:
    Since the radius of circle O is 2 and the radius of circle P is 6, OP = 2+6 or 8. Hence, the circumference of any circle that has OP as a diameter is 8π.

  • 第13题:

    ( 13 )补充完整下面的类定义:

    const double PI=3 .14;

    class Circle{ // 圆形物体的抽象基类

    protected:

    double r; // 半径

    public:

    Circle ( double radius=0 ) : r ( radius ) {}

    【 13 】 ; // 计算圆形物体表面积的纯虚函数声明

    };

    class Cylinder:public Circle { // 圆柱体类

    double h; // 高度

    public:

    Cylindr ( double radius=0, doubli height=0 ) :

    Circle ( radius ) , h ( height ) {}

    Virtual double Area () { // 计算圆柱体的表面积

    return 2*PI*r* ( r+h ) ;

    }

    };


    正确答案:

  • 第14题:

    描述以(1000,1000)为圆心、以400为半径画1/4圆弧的语句,以下正确的是( ) 。

    A、Circle(1000,1000),400,0,3.1415926/2

    B、Circle(1000,1000),,400,0,3.1415926/2

    C、Circle(1000,1000),400,,0,3.1415926/2

    D、Circle(1000,1000),400,,0,90


    正确答案:C


  • 第15题:

    有如下类定义:

    class Point{

    public:

    Point(int xx=0,int yy=0):x(xx),y(yy) { }

    private:

    int x,y;

    };

    class Circle:public Point{

    public:

    Circle(int r):radius(r) { }

    private:

    int radius;

    };

    派生类Circle中数据成员的个数是( )。

    A、3

    B、1

    C、5

    D、2


    答案:A
    解析:本题考查默认构造函数和带参数的构造函数,题目中定义一个对象a(2)以及对象数组b[3],共执行3次构造函数,对象指针不调用构造函数。


  • 第16题:

    使用VC6打开考生文件夹下的工程test9_3,此工程包含一个源程序文件test9_3.cpp,其中定义了Circle类与Money类, Circle类可对半径为r的圆进行周长与面积的计算,而Money类用于计算一圆形游泳池的造价。游泳池四周有原形过道,过道外围上栅栏,过道宽度为3米,根据键入的游泳池半径,每米栅栏价格及每平方米过道价格,即可计算出游泳池的造价。请按要求完成下列操作,将程序补充完整。

    (1)定义符号常量PI(值为3.14159f)与WIDTH(值为3.00f),分别用于表示圆周率与过道的固定宽度。请在注释“//**1**”之后添加适当的语句。

    (2)定义Circle类默认构造函数,把私有成员radius初始化为参数r的值。请在注释 “//**2**” 后添加适当的语句。

    (3)完成Money类默认构造函数的定义,把私有成员FencePrice(每米栅栏的价格)、ConcretePrice(每平方米过道的价格)初始化为参数f,c的值。请在注释“//**3**”之后添加适当的语句。

    (4)完成Money类成员函数floatMoney::TotalMoney(noat fencelen,float conarea)的定义,根据参数fencelen(栅栏的长度)和conarea(过道的面积),返回栅栏与过道的总造价。请在注释“//**4**”之后添加适当的语句。

    注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。

    源程序文件test9_3.cpp清单如下:

    include<iostream.h>

    //**1**

    class Circle

    {

    private:

    float radius;

    public:

    //**2**

    float Circumference(){return 2 * PI * radius;)

    float Area(){return PI * radius * radius;)

    };

    class Money

    {

    private:

    float FencePrice;

    float ConcretePrice;

    public:

    Money(float f,float c);

    float TotalMoney(float fencelen, float conarea);

    };

    Money::Money(float f,float c)

    {

    //**3**

    }

    float Money::TotalMoney(float fencelen,float conarea)

    {

    //**4**

    }

    void main()

    {

    float radius,fence,concrete;

    cout.setf(10s::fixed);

    cout.setf(ios::showpoint);

    cout.precision(2);

    cout<<"Enter the radius of the pool:";

    cin>>radius;

    cout<< "Enter the FencePrice:";

    cin>>fence;

    cout<<"Enter the ConcretePrice:";

    cin>>concrete;

    Circle Pool(radius);

    Circle PoolRim(radius + WIDTH);

    Money mon(fence,concrete);

    float totalmoney=mon.TotalMoney(PoolRim.Circumference(),(PoolRim.Area() - P00l.Area()));

    cout<<"The total money is RMB"<<totalmoney<<endl;

    }


    正确答案:(1) const float PI=3.14159f; const float WIDTH=3.00f; (2) Circle(noat r):radius(r){}; (3) FencePrice=f; ConcretePrice=c; (4) return FencePrice*fencelen+ConcretePrice*conarea;
    (1) const float PI=3.14159f; const float WIDTH=3.00f; (2) Circle(noat r):radius(r){}; (3) FencePrice=f; ConcretePrice=c; (4) return FencePrice*fencelen+ConcretePrice*conarea; 解析:本题考查了考生对符号常量的定义及类的定义与实现等方面的内容。注意常类型的定义应使用const关键字。

  • 第17题:

    阅读下列程序说明和C++代码,将应填入(n)处的字句写在对应栏内。

    [说明]

    ①为类Circle增加一个构造函数,该函数有一个参数,并在构造时将该参数值赋给成员 radius。将该函数实现为一个非内联函数,并且使用参数列表的方式将类成员赋值。

    ②为类Circle增加一个成员函数print(),使得可以输出有关圆的信息,比如下列程序

    Circle c;

    c. SetRadius(5);

    c. Print();

    将输出:The circle has radius of 5!

    ③完成友元函数void CompareR(Circle *c1,Circle *c2)的定义,在屏幕中输出c1与c2比较radius大小结果,要求使用if - else结构完成。

    输出结果如下:

    The circle has radus of 5 !

    The circle has radius of 10 !

    cl <c2

    源程序文件test7_3, cpp 清单如下:

    include < iostream, h >

    class Circle {

    public:

    Circle( ) :radius(5) {}

    (1)

    void SetRadius(int r) { radius = r; }

    int GetRadius() { return radius; }

    (2)

    friend void CompareR(Circle * c1,Circle * c2);

    private:

    int radius;

    };

    void CompareR(Circle * c! ,Circle * c2)

    {

    (3)

    cout << "c1 > c2" << endl;

    else

    if ( (c1 -> GetRadius( )) == (c2 -> GetRadius( )))

    tout < <"c1=c2' < < endl;

    else

    if ( (c1 -> GetRadius( )) < ( c2 -> GetRadius( )))

    cout <<"c1<c2" <<endl;

    void main( )

    Circle c1

    c1. SetRadius(5)

    c1. Print( )

    Circle c2(10);

    c2. Print( )

    CompareR(&c1 ,&c2);

    }


    正确答案:(1)Circle(int rad):radius(rad){} (2)void Print(){cout "The circle has radius of" radius "!\n";} (3)if((c1->GetRadius())>(c2-->GetRadius()))
    (1)Circle(int rad):radius(rad){} (2)void Print(){cout "The circle has radius of" radius "!\n";} (3)if((c1->GetRadius())>(c2-->GetRadius())) 解析:本题考查成员函数的定义与实现,友元函数,if分支语句等知识点。友元函数的类体外的定义与一般函数一样,注意(3)中if- else的使用,else总是与其最近的那个if配对使用的,书写时最好使用缩进格式,将配对的if-else对齐,以免出错。

  • 第18题:

    有如下程序: include using namespace std; class Point{ int x, y; public: Point(i

    有如下程序:

    #include<iostream>

    using namespace std;

    class Point{

    int x, y;

    public:

    Point(int x1=0, int y1=0):x(x1), y(y1){}

    int get(){return x+y;)

    };

    class Circle{

    Point center;

    int radius;

    public:

    Circle(int CX, int cy, int r):center(cx, cy), radius(r){}

    int get(){return center. get()+radius;}

    };

    int main(){

    circle c(3, 4, 5);

    cout<<c. get()<<end1;

    return ():

    }

    运行时的输出结果是( )。

    A) 5

    B) 7

    C) 9

    D) 12

    A.

    B.

    C.

    D.


    正确答案:D

  • 第19题:

    编写一个圆类Circle,该类拥有()


    答案:①一个成员变量Radius(私有,浮点型);? // 存放圆的半径;②两个构造方法Circle( )???????????????? // 将半径设为0Circle(double? r )???????? //创建Circle对象时将半径初始化为rclass Circle{private double Radius;Circle(){Radius=0.0;}public Circle(double r){this. Radius= r;}}

  • 第20题:

    阅读以下说明和Java程序,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
    【说明】
    以下Java代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分接口、类及其关系如图5-1所示。




    【Java代码】
    interface?DrawCircle?{? //绘制圆形 public(1) ;}class?RedCircle?implements?DrawCircle?{? ?//绘制红色圆形???????public?void?drawCircle(int?radius,intx,?int?y)??{????????????System.out.println("Drawing?Circle[red,radius:"?+?radius?+",x:"?+?x?+?",y:"?+y+?"]");???????}}class?GreenCircle?implements?DrawCircle?{????//绘制绿色圆形??????public?void?drawCircle(int?radius,?int?x,int?y)?{???????????System.out.println("Drawing?Circle[green,radius:"?+radius+",x:?"?+x+?",y:?"?+y+?"]");??????}}abstract?class?Shape?{????//形状? protected? ? (2)???;? ? public?Shape(DrawCircle?drawCircle)?{? ?this.drawCircle=?drawCircle;? ? ? public?abstract?void?draw();}class?Circle?extends?Shape?{? //圆形? ?private?int?x,y,radius;? public?Circle(int?x,int?y,intradius,DrawCircle?drawCircle)?{? ?(3)???;? this.x?=?x;? ? ? this.y?=?y;? ?this.radius?=radius;? }? ? ?public?void?draw()?{? ? drawCircle.? ?(4)? ?;? ? ? }}public?class?DrawCircleMain?{? public?static?void?main(String[]?args)?{? Shape?redCircle=new?Circle(?100,100,10,? (5) );//绘制红色圆形? Shape?greenCircle=new?Circle(200,200,10,(6) );//绘制绿色圆形? ?redCircle.draw(); greenCircle.draw();? ?}}


    答案:
    解析:
    (1)void drawCircle (int radius,int x,int y)
    (2)DrawCircle drawCircle
    (3)super.drawcircle=drawcircle
    (4)drawCircle(radius,x,y)
    (5)new RedCircle()
    (6)new GreenCircle()【解析】
    第一空是填接口里面的方法,在接口的实现里面找,可以发现应该填void drawCircle (int radius,int x,int y)。
    第二空可以根据后面this drawCircle=drawCircle判断,这里应该有一个drawCircle属性,因此应该填)DrawCircle drawCircle。
    第三空这里用super,用super. drawcircle来引用父类的成员。
    第四空调用drawCircle(radius,x,y)方法。
    第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。

  • 第21题:

    无序列表的属性值circle表示()。

    • A、方块
    • B、空心圆
    • C、实心圆
    • D、以上都不对

    正确答案:B

  • 第22题:

    单选题
    A circle with center A has its center at (6, -2) and a radius of 4. Which of the following is the equation of a line tangent to the circle with center A ?
    A

    y=3x+2

    B

    y=2x+1

    C

    y=-x+5

    D

    y=-2

    E

    y=-6


    正确答案: A
    解析:
    切线指与圆相交且与圆只有一个焦点的线。A、B与圆不相交。C、D 与圆相交且有两个交点。只有E项符合。

  • 第23题:

    多选题
    public abstract class Shape {  private int x;  private int y;  public abstract void draw();  public void setAnchor(int x, int y) {  this.x = x;  this.y = y;  }  }  Which two classes use the Shape class correctly?()
    A

    public class Circle implements Shape { private int radius; }

    B

    public abstract class Circle extends Shape { private int radius; }

    C

    public class Circle extends Shape { private int radius; public void draw(); }

    D

    public abstract class Circle implements Shape { private int radius; public void draw(); }

    E

    public class Circle extends Shape { private int radius;public void draw() {/* code here */} }

    F

    public abstract class Circle implements Shape { private int radius;public void draw() { / code here */ } }


    正确答案: B,E
    解析: 暂无解析

  • 第24题:

    单选题
    If the ratio of the area of a sector to the area of the circle is 2:3. what is the ratio of the length of the arc in the sector to the circumference of the circle?
    A

    3/2

    B

    2/3

    C

    4/9

    D

    1/4

    E

    9/4


    正确答案: D
    解析:
    The ratio of sector area to circle area is proportional to the ratio of sector arc length to circumference.