第十周任务三
来源:互联网 发布:能看阿衰漫画的软件 编辑:程序博客网 时间:2024/06/05 14:49
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者: 李超
* 完成日期: 2012 年 4 月 25 日
* 版 本 号: 01.10.03
* 对任务及求解方法的描述部分
主函数main.cpp
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:
* 作 者: 李超
* 完成日期: 2012 年 4 月 25 日
* 版 本 号: 01.10.03
* 对任务及求解方法的描述部分
* 程序输出:
坐标为:(1,2)
圆ci:坐标为:(1,2)半径为:3
改变后的圆ci:坐标为:(4,5)半径为:6
圆柱cl:坐标为:(2,3)半径为:1高为:4
改变后的圆柱cl:坐标为:(4,5)半径为:6高为:7
* 程序头部的注释结束
*感言:该题 好麻烦, 最终还是不知道析构函数怎么弄
*/
头文件LCylinder.h
#include <iostream>using namespace std;double P = 3.14159;class Point{public:Point(double x1 = 0, double y1 = 0): x(x1), y(y1){}//数据初始化friend ostream & operator << (ostream &, Point &);//重载<<void Change1(double x1,double y1){x = x1;y = y1;}//改变数据double GetX(){return x;}//得到xdouble GetY(){return y;}//得到yprivate:double x;//横坐标double y;//纵坐标};class Circle:public Point{public:Circle (double x1 = 0, double y1 = 0, double r1 = 1):Point(x1, y1),r(r1){}double GetR(){return r;}//得到半径void Change2 (double x1,double y1,double r1){Change1(x1,y1);r = r1;}//改变数据friend ostream & operator <<(ostream &, Point &);//重载<<private:double r;//半径};class Cylinder:public Circle{public:Cylinder(double x1 = 0, double y1 = 0,double r1 = 1, double h1 = 1):Circle (x1, y1, r1), h(h1){}double GetH(){return h;}//得到高double Area();//计算圆柱面积double Volume();//计算圆柱体积void Change3(double x1,double y1,double r1,double h1){Change2(x1,y1,r1);h = h1;}//改变数据friend ostream & operator << (ostream &, Cylinder & c);//重载<<private:double h;//高};ostream & operator << (ostream &output, Point & c){output <<"坐标为:" <<'(' <<c.GetX ()<<',' <<c.GetY () <<')';return output;}ostream & operator << (ostream &output, Circle & c){output <<"坐标为:" <<'(' <<c.GetX () <<',' <<c.GetY () <<')' <<"半径为:" <<c.GetR ();return output;}ostream & operator << (ostream &output, Cylinder & c){output <<"坐标为:" <<'(' <<c.GetX () <<',' <<c.GetY () <<')' <<"半径为:" <<c.GetR () <<"高为:" <<c.GetH ();return output;}double Cylinder::Area(){return (2 * GetR () * GetR () * P + 2 * P * GetR () * h);}double Cylinder::Volume(){return (2 * GetR () * GetR () * P * h);}
主函数main.cpp
#include <iostream>#include"LCylinder.h"using namespace std;void main(){Point p1(1,2);cout <<p1 <<endl;Circle ci(1,2,3);cout <<"圆ci:" <<ci <<endl;ci.Change2 (4,5,6);cout<<"改变后的圆ci:" <<ci <<endl;Cylinder cl(2,3,1,4);cout <<"圆柱cl:";cout <<cl <<endl;cl.Change3 (4,5,6,7);cout <<"改变后的圆柱cl:";cout <<cl <<endl;system("pause");}
- 第十周 任务三
- 第十周任务三
- 第十周任务三
- 第十周任务三
- 第十周任务三
- 第十周任务三
- 第十周任务三
- 第十周 任务三
- 第十周任务(三)
- 第十周作业任务三
- 第十周实验报告 任务三
- 第十四周任务三
- 第十周任务三 多重继承派生类
- 第十周实验报告(任务三)【派生类2】
- 第十周实验报告 任务三(改)
- 第十周任务三:派生类的派生
- 第十周任务三之点类及多重派生
- 第十周任务一:三种循环求和的方法
- Android Animation 高手必读 之一 Tweened Animations 代码实现
- 定向抓取漫谈
- Linux系统下C开发MySQL数据库应用
- [转]Android 的大牛的博客
- linux下bus,device,driver三者关系
- 第十周任务三
- JSF下dataGrid与Action绑定问题
- linux spi子系统
- android中Intent的一些用法和总结
- 研究发现太阳提前出现磁极反转将现活动高峰期
- 代替cmd的一个好用的工具 powercmd
- 最大的子序列和问题
- 和别人共享网络,老有人用讯雷什么的,上网卡死了,自己写了局域网流量控制工具,开源出来大家共享
- vkeyi项目架构设计总结