lintcode-454. Rectangle Area

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/richenyunqi/article/details/80689346

欢迎访问我的lintcode题解目录https://blog.csdn.net/richenyunqi/article/details/81149577

Java代码:

public class Rectangle {
    /*
     * Define two public attributes width and height of type int.
     */
    // write your code here
    private int width;
    private int height;
    /*
     * Define a constructor which expects two parameters width and height here.
     */
    // write your code here
    public Rectangle(int w,int h)
    {
        width=w;
        height=h;
    }
    /*
     * Define a public method `getArea` which can calculate the area of the
     * rectangle and return.
     */
    // write your code here
    public int getArea()
    {
        return width*height;
    }
}

 

 

 

error: undefined reference to `Circle::Circle()' and `Rectangle::Rectangle()'

05-26

题目如下:rn[quote]以点(Point)类为基类,重新派生类 Rectangle、Circle。坐标原点为(0,0),矩形水平放置,由左下方的顶点和长宽定义。rnrn圆由圆心和半径定义。派生类操作判断任一坐标点是在图形内,还是在图形的边缘上,还是在图形外。rnrn缺省初始化图形退化为坐标原点(0,0)rnrn要求拷贝构造函数和定义默认构造函数rnrn编程测试类设计是否正确。rnrnclass Pointrnrnprivate:rn double x,y;rnpublic:rn Point();rn Point(double xv,double yv);rn Point(Point& pt);rn double getx();rn double gety();rn;rn rn类Circle 和类Rectangle 都包含成员函数:int position(Point &pt)。 rn rn假如点A落在圆内或是矩形内,则该函数返回-1;如果落在圆上或是矩形上,则返回0,;如果落在外面,则返回1。rn rn主函数:rnint main()rnrn Circle cc1(3,4,5);rn Rectangle rt1(0,0,6,8);rn Point p1(0,0);rn cout<<"point p1:";rn switch(rt1.position(p1))rn rn case 0:cout<<"on-rectangle"<rnusing namespace std;rnclass Pointrnrnprotected:rn double x,y;rnpublic:rn Point();rn Point(double x,double y):x(x),y(y)rn Point(Point& pt);rn double getx() const return x;rn double gety() const return y;rn;rnPoint::Point(Point& pt)rnrn x=pt.x;y=pt.y;rnrnclass Circle:public Pointrnrnprotected:rn int r;rnpublic:rn Circle();rn Circle(double x,double y, int r):Point(x,y),r(r)rn int getr() const return r;rn int position(Point &pt);rn;rnint Circle::position(Point &pt)rnrn int ireturn=0;rn int temp=0;rn int temp0=r*r;rn temp = (pt.getx()-x)*(pt.getx()-x)+(pt.gety()-y)*(pt.gety()-y);rn if(temp == temp0)rn rn ireturn = 0;rn rn else if (temp < temp0)rn rn ireturn = -1;rn rn elsern rn ireturn = 1;rn rn return ireturn;rnrnclass Rectangle:public Pointrnrnprotected:rn int length,width;rnpublic:rn Rectangle();rn Rectangle(double x,double y,int length,int width):Point(x,y),length(length),width(width)rn int getlength() const return length;rn int getwidth() const return width;rn int position(Point &pt);rn;rnint Rectangle::position(Point& pt)rnrn int ireturn = 0;rn rn if (pt.getx()==x||pt.gety()==y||pt.getx()==x+length||pt.gety()==y+width)rn rn ireturn = 0;rn rn else if (pt.getx()>x&&pt.getx()y&&pt.gety()

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试