C++问题:设计一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算矩形的面积
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 06:12:55
C++问题:设计一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算矩形的面积
利用组合类,能运行的话会追加分~
利用组合类,能运行的话会追加分~
给你两种 写法
第一种:
#include
#include
class Rectangle
{
public:
Rectangle(int left,int bottom,int right,int top);
Rectangle(){ }
//int GetLeft() {return itsLeft;}
int GetBottom() {return itsBottom;}
int GetRight() {return itsRight;}
int GetTop() { return itsTop;}
void SetLeft(int left) {itsLeft=left;}
void SetBottom(int bottom) {itsBottom=bottom;}
void SetRight(int right) {itsRight=right;}
void SetTop(int top) {itsTop=top;}
int GetArea();
private:
int itsLeft;
int itsBottom;
int itsRight;
int itsTop;
int Width;
int Height;
};
Rectangle::Rectangle(int left,int bottom,int right,int top)
{
itsLeft=left;
itsBottom=bottom;
itsRight=right;
itsTop=top;
}
int Rectangle::GetArea()
{
Width=abs(itsRight-itsLeft);
Height=abs(itsTop-itsBottom);
cout
第一种:
#include
#include
class Rectangle
{
public:
Rectangle(int left,int bottom,int right,int top);
Rectangle(){ }
//int GetLeft() {return itsLeft;}
int GetBottom() {return itsBottom;}
int GetRight() {return itsRight;}
int GetTop() { return itsTop;}
void SetLeft(int left) {itsLeft=left;}
void SetBottom(int bottom) {itsBottom=bottom;}
void SetRight(int right) {itsRight=right;}
void SetTop(int top) {itsTop=top;}
int GetArea();
private:
int itsLeft;
int itsBottom;
int itsRight;
int itsTop;
int Width;
int Height;
};
Rectangle::Rectangle(int left,int bottom,int right,int top)
{
itsLeft=left;
itsBottom=bottom;
itsRight=right;
itsTop=top;
}
int Rectangle::GetArea()
{
Width=abs(itsRight-itsLeft);
Height=abs(itsTop-itsBottom);
cout
C++问题:设计一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算矩形的面积
设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角和右上角两个点的坐标,能计算矩形的面积.
设计并测试一个名为Retangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积
设计一个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积.要有构造函数并实现,
c++问题: 定义一个名为rectangle的矩形类,其属性数据为矩形左上角和右下角的点的坐标,能计算矩形的面积
设计一个矩形类Rectangle,计算矩形的面积之和!
实现Rectangle类,含有两个方法:构造方法Rectangle()和计算面积的方法,计算矩形面积.急
C++设计一个矩形类(Rectangle),可以求矩形的周长和面积?急!求高手帮忙?
c#定义一个类圆Circle或者定义一个矩形类Rectangle,分别计算它们的周长和面积.
C++定义描述矩形的类Rectangle,其数据成员为矩形的中心坐标(X,Y)、长(Length)与宽(Width).
java 定义一个矩形类,有长、宽2个属性,有成员函数计算矩形的面积.
(3) 编程实现矩形类Rectangle,其中应包括计算矩形周长的方法perimeter()和计算面积的方法Area()