C第08章类及对象(例子).docVIP

  • 3
  • 0
  • 约 22页
  • 2017-05-20 发布于北京
  • 举报
C第08章类及对象(例子)

例8.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) { coutArea = ; coutabs(right-left)* abs(bottom-top)endl; } }; void CRect::setcoord(int L, int T, int R, int B) { left=L; top=T; right=R; bottom=B; } void main(void) { CRect r, rr; int a, b, c, d ; r

文档评论(0)

1亿VIP精品文档

相关文档