C++圆锥体类(最新整理)_第1页
C++圆锥体类(最新整理)_第2页
C++圆锥体类(最新整理)_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、#include #includeclass y1/为半径和高赋值public:y1()/无参数构造函数的调用r=2;h=2;cout无参构造函数调用!r=rh=hendl;y1(double a,double b)/有参构造函数调用r=a;h=b;cout有参构造函数调用!r=rh=hendl;y1(y1 &p);/复制构造函数调用y1()/析构函数调用cout析构函数调用!r=rh=hendl;friend void tj(y1 &a);/友元函数声明static void print1();/静态成员函数声明void print2() const;/常成员函数声明private:doub

2、le r,h; static double p;double y1:p=3.14;/静态成员函数赋初值y1:y1(y1 &p)/复制构造函数r=p.r;h=p.h;cout复制构造函数调用!r=rh=hendl;void y1:print1()cout=pendl;cout静态成员函数被调用!n;void y1:print2() constcout半径:rt高:hendl; cout常成员函数被调用!n;void tj(y1 &a)/友元函数体积cout体积:a.p*a.r*a.r*a.h/3endl; cout友元函数被调用!n;/面积class y2double r,h,p;public:

3、y2()/无参构造函数调用r=1;h=1;p=3.14;cout无参构造函数调用!r=rh=hendl;y2(double a,double b)/有参构造函数调用r=a;h=b;p=3.14;cout有参构造函数调用!r=rh=hendl;y2()/析构函数调用cout析构函数调用!r=rh=hendl;void print3 ()cout表面积:p*r*sqrt(h*h+r*r)+p*r*rendl;/汇总class yuan:public y2/单继承y1 a;/子对象public:yuan()cout无参构造函数调用!n; yuan(double a,double b):a(a,b),

4、y2(a,b)cout有参构造函数调用!n;yuan()/析构函数调用cout析构函数调用!n;void print4()y2:print3();/tj();void main()int i=2; double r,h;coutn*圆锥体类的实现*张志强制endl; coutn*无参程序运行*nn;yuan a;y1:print1();consty1 w(1,1); w.print2();couti;for(;i!=0;)coutn*有参程序运行*n; coutendl;coutr; couth; y1 q(r,h);yuan s(r,h);y1:print1();s.print4();y1

5、p=q;tj(p);couti;“”“”at the end, xiao bian gives you a passage. minand once said, people who learn to learn are very happy people. in every wonderful life, learning is an eternal theme. as a professional clerical and teaching position, i understand the importance of continuous learning, life is dilig

6、ent, nothing can be gained, only continuous learning can achieve better self. only by constantly learning and mastering the latest relevant knowledge, can employees from all walks of life keep up with the pace of enterprise development and innovate to meet the needs of the market. this document is also edited by my studio pro

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论