编写面向对象的程序,定义一个求矩 形面积的类 Rect。具体要求如下 c#求长方形面积
java 编写一个矩形类 rect 要求如下:
public class Rect{
private int length;
private int width;
private int startX;
private int startY
public Rect(){}
public Rect(int length,int width){
this.length = length;
this.width = width;
}
public Rect(int length,int width,int startX,int startY){
this.length = length;
this.width = width;
this.startX = startX;
this.startY = startY;
}
//不知道你要什么成员方法,我随便点....
public void louzhuhao(){
System.out.println("楼主好....");
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getStartX() {
return startX;
}
public void setStartX(int startX) {
this.startX = startX;
}
public int getStartY() {
return startY;
}
public void setStartY(int startY) {
this.startY = startY;
}
}
编写一个矩形类Rect
#define UINT unsigned int
#define ULONG unsigned long
class Rect_lv
{
public:
UINT width;
UINT height;
Retc_lv(UINT,UINT);
Retc_lv();
ULONG area();
UINT perimeter();
};
Retc_lv::Retc_lv(UINT w,UINT h)
{
width=w;
height=t;
}
Retc_lv::Retc_lv()
{
width=10;
height=10;
}
ULONG Retc_lv::area()
{
return width*height;
}
UINT Retc_lv::perimeter()
{
return (width+height)*2;
}
C++设计 定义一个矩形类Rect 急求啊
#include
using namespace std;
class rect
{
public:
rect(int width, int length) : width(width),length(length){}
int area()
{
return length * width;
}
int perimeter()
{
return 2 * (length + width);
}
friend int add(rect &r1, rect &r2);
private:
int length;
int width;
};
int add(rect &r1,rect &r2)
{
return r1.area() + r2.area();
}
int main()
{
rect rect1(2,4), rect2(4,6);
cout<<"rect1的面积是"< cout<<"rect1的周长是"< cout<<"rect2的面积是"< cout<<"rect2的周长是"< cout<<"rect1 和rect2的面积之和为"< return 0;
}
运行结果
rect1的面积是8
rect1的周长是12
rect2的面积是24
rect2的周长是20
rect1 和rect2的面积之和为32
press any key to continue