网上法院起诉:关于c++程序设计

来源:百度文库 编辑:神马品牌网 时间:2024/05/09 09:43:57
设计并测试一个名为Rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,能计算矩形的面积。 请朋友们帮帮忙,OK?
是一个矩形的面积,不是两个的面积。是根据坐标算的。

#include<iostream.h>
struct point
{
float x,y;
};
class Rectangle
{
private:
float length,width;
point p1,p2;
float area;
public:
Rectangle()
{
cout << "please input the point 1 (x,y):";
cin >> p1.x >> p1.y;
cout << "please input the point 2 (x,y):";
cin >> p2.x >> p2.y;
length = p2.x -p1.x;
width = p2.y - p1.y;
area=length*width;
}
void Display()
{
cout << endl;
cout << "area:" << area << endl;
}
};
void main()
{
Rectangle obj;
obj.Display();
}

#include<iostream.h>
class Rectangle;
class Circle
{
private:
float radius;
float area;
public:
Circle(float x)
{
radius=x;
area=3.14*radius*radius;
}
friend double area_add(Circle Cobj1,Rectangle Robj1);
};
class Rectangle
{
private:
float length,width;
float area;
public:
Rectangle(float l,float w)
{
length=l;
width=w;
area=length*width;
}
friend double area_add(Circle Cobj1,Rectangle Robj1);
};
double area_add(Circle Cobj1,Rectangle Robj1)
{
return Cobj1.area+Robj1.area;
}
void main()
{
Circle obj1(2);
Rectangle obj2(3,3);
cout<<"两个平面图形的面积之和为:"<<area_add(obj1,obj2)<<endl;
}