#include<iostream>
#include<cmath>
classpoint{doublex;doubley;public: point(doublea=0,doubleb=0){ x=a;y=b;}
voidset(doublea,doubleb){x=a;y=b;}
doublegetX(){returnx;}doublegetY(){returny;}};
classRectangle{
private:
pointlpoint,rpoint;
public:
Rectangle(pointl,pointr)
{
lpoint=l;
rpoint=r;
}
doubleArea()
{
returngetlength()*getwidth();
}
doublegetlength()
{
return<ahref="http://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3n1DLrAwhrj63mHF-uAPh0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH0YP1bzn10zP1m4PWb1PWR1rf"target="_self"class="baidu-highlight">abs</a>(lpoint.getX()-rpoint.getX());
}
doublegetwidth()
{
return<ahref="http://www.baidu.com/s?wd=abs&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3n1DLrAwhrj63mHF-uAPh0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH0YP1bzn10zP1m4PWb1PWR1rf"target="_self"class="baidu-highlight">abs</a>(lpoint.getY()-rpoint.getY());
}
}
intmain()
{
pointlt,rb;
doublea,b;
cout<<"输入左上角坐标: ";
cin>>a>>b;
lt.set(a,b);
cout<<"输入右下角坐标: ";
cin>>a>>b;
rb.set(a,b);
Rectangle rt(lt,rb);
cout<<"矩形的面积等于"<<rt.Area()<<endl;
return0;
}
Rectangle是一个函数,使用该函数画一个矩形,可以用当前的画笔画矩形轮廓,用当前画刷进行填充。函数原型:BOOLRectangle(HDChdc,intnLeftRect,intnTopRect,intnRightRect,intnBottomRect);
如何设计一个名为Rectangle的矩形类?
Rectangle是一个函数,使用该函数画一个矩形,可以用当前的画笔画矩形轮廓,用当前画刷进行填充。函数原型:BOOLRectangle(HDChdc,intnLeftRect,intnTopRect,intnRightRect,intnBottomRect);
C++问题:设计一个名为Rectangle的矩形类,其属性为矩形的左下角和右...
cout<<"该矩形的长:"<<Width<<endl;cout<<"该矩形的宽:"<<Height<<endl;return (Width*Height);} void main(){ Rectangle MyRectangle(20,20,60,50);int Area;Area=MyRectangle.GetArea();cout<<"Area:"<<Area<<endl;MyRectangle.SetLeft(10);Area=MyRectangle.GetArea();cout<<"Area...
2、创建一个名为Rectangle的类来表示一个矩形
public class Rectangle{ double length ,width; \/\/定义两个变量长,宽 public double getArea()\/\/定义获得面积的方法 { return width*length;} public double getPerimeter()\/\/定义获得周长的方法 { return 2*(width+length);} \/\/构造方法 public Rectangle(double length,double width)...
4. 设计并测试一个名为Rectangle的矩形类
Rectangle(double l=0, double t=0, double r=0, double b=0);~ Rectangle(){}; \/\/析构函数,在此函数体为空 void Assign(double l,double t,double r,double b);double getLeft(){ return left;} \/\/ 以下四个函数皆为内联成员函数 double getRight(){ return right;} double getTo...
定义一个矩形类Rectangle,数据成员(矩形长,宽),成员函数(给长宽赋值...
class Rectangle {private:float length,width;public:void setRectangle(float &m,float &n){length=m; width=n; };float girth(){return 2*(length+width);};float area(){return length*width;};};void main(){ float m=20;\/\/也可以为别的数 float n=30;\/\/也可以为别的数 Rectang...
.编写一个名为Rectangle的JAVA类来表示矩形
public class Rectangle { double width;double height;string color;public void setWidth(double width) { this.width = width;} public void setHeight(double height) { this.height = height;} public void setColor() { this.color = color;} public double getWidth() { return width;} pu...
2、设计并测试一个名为Rectangle的矩形类,
public class Rectangle {double chang,kuan;public double getArea(double chang,double kuan){return chang*kuan;}public double getPerimeter(double chang,double kuan){return (chang+kuan)*2;}public Rectangle(){}public Rectangle(double chang,double kuan){if(0 ...
JAVA,写一个名为Rectangle的类表示矩形,怎么写?
1。颜色题目没初始化,我定义为“black”2。 测试函数具体没说测试什么,以及长宽没初始化数值,故代码中只调用toString()方法,具体自己改写 public class Test { public static void main(String[] args){ Rectangle r1 = new Rectangle(2.3,5.2);System.out.println(r1.toString());} } ...
设计并测试一个名为Rectangle的类表示矩形,其属性为矩形的左下角和右...
Rectangle(double x1,double y1,double x2,double y2):p1(x1,y1),p2(x2,y2){ } double GetLength(){ return fabs(p2.x-p1.x);} double GetArea(){ return fabs((p2.x-p1.x) * (p2.y-p1.y));} private:point p1,p2;};void main(){ Rectangle r(1,2,3,4);cout <<r...
定义一个名为rectangle的矩形类,其属性数值为矩形的左上角和右下角的...
class rectangle { public:double upper_left_x, upper_left_y, lower_right_x, lower_right_y;rectangle(double ulx, double uly, double lrx, double lry):upper_left_x(ulx), upper_left_y(uly), lower_right_x(lrx), lower_right_y(lry){} };double area(const rectangle& rec){...