例 10.4 定义并测试长方形类 CRect,长方形是由左上角
坐标(left, top)和右下角坐标(right, bottom)组成。
#include <iostream.h>
#include <math.h>
class CRect //定义长方形类
{
private:
int left, top, right, bottom ;
public:
void setcoord(int, int, int, int);
void getcoord(int *L, int *T, int *R, int *B)
//注意:形参为指针变量
{
*L = left; *T = top;
*R = right; *B = bottom;
}
void print(void)
{
cout<<"Area = ";
cout<<abs(right-left)*
abs(bottom-top)<<endl;
}
};