第05章程序结构6课时中类的习题课.pptxVIP

  • 0
  • 0
  • 约3.22千字
  • 约 24页
  • 2022-07-06 发布于北京
  • 举报
习题课;(2)成员函数的实现——类的定义;void tree::age( ) { coutThe trees age is : agesendl; };4-9、用组合类的方式改写Rectangle类。;Point::Point(double xx,double yy) { x=xx; y=yy; } Point::Point(Point p) { x=p.x; y=p.y; };class Rectangle { public: Rectangle(Point pp1,Point pp2); Rectangle(Rectangle Rect); ~Rectangle( ){ } double GetArea ( ){return area;} private: Point p1,p2; double area; };;Rectangle::Rectangle(Point pp1,Point pp2) :p1(pp1),p2(pp2) { double width=fabs(pp1.GetX( )-pp2.GetX( )); double length=fabs(pp1.GetY( )-pp2.GetY( )); area=width*length; };int main() { double x1,y1,x2,y2; coutPlease Input

文档评论(0)

1亿VIP精品文档

相关文档