[C++]运算符重载实验报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

+operator+(const COMPLEX &other): COMPLEX

+operator-(const COMPLEX &other) : COMPLEX

+operator-(): COMPLEX

+operator=(const COMPLEX &other) : COMPLEX

运行结果

2. 程序的类结构图为:

T

x,y:int

+T(int a,int b)

+&operator<<(ostream &os,T &a):friend ostream

运行结果

3. 程序的类结构图为:

Shape

+Area():virtual double const

+PrintShapeName():virtual void const +Print():virtual void const

Point

x,y:int

+Point(int=0,int=0)

+SetPoint(int a,int b):void

+GetX():int const

+GetY():int const

+PointShapeName():virtual void const +Print():virtual void const

Circle

radius:double

+Circle(int x=0,int y=0,double r=0.0) +SetRadius(double r):void

+GetRadius():double const

+Area():virtual double const

+Print():virtual void const

+PrintShapeName():virtual void const 运行结果

{

cout<<'['<

int main()

{

Circle1 circle(0.0,0.0,3.0);

circle.area();

circle.perimeter();

circle.print();

cout<<"\n";

Square1 square(0.0,0.0,3.0,3.0);

square.area();

square.perimeter();

square.print();

cout<<"\n";

cout<<"圆的面积为:"<

cout<<"圆的周长为:"<

cout<<"圆的圆心坐标和半径为:";

circle.print();

cout<<"\n\n";

cout<<"正方形的面积为:"<

cout<<"正方形的周长为:"<

cout<<"正方形的中心坐标和一个顶点坐标分别为:";

square.print();

cout<<"\n";

return 0;

}

运行结果

【实例编程】

运行结果

相关文档
最新文档