




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
下面给出的是几对实体。请按“isa(是hasa(具有norelationhasnonohasishashashashasis 析构函 构造函 数据成 类的public成员函数集称为类 对外接 重载,类的析构函 不能 #if!defined_NUMBERCRUNCHER_H_#define_NUMBERCRUNCHER_H_class{doublex;NumberCruncher(double{doubleget();doubletwice();doubletriple();doublesquare();doublecube();#include"numbercruncher.h"#include<iostream>//usingnamespacedoubleNumberCruncher::get(){returnx;//注意缩进}doubleNumberCruncher::twice(){return2*x;//注意缩进}doubleNumberCruncher::triple(){return3*x;//注意缩进}doubleNumberCruncher::square(){returnx*x;//注意缩进}doubleNumberCruncher::cube(){returnx*x*x;//注意缩进}#include//写#include<cstdlib>usingnamespaceint{intNumberCruncherr(a);cout<<"输入的值为"<<r.get()<<",2倍值"<<r.twice()<<",3值"<<r.triple()<<",平方值"<<r.square()<<",立方return0;}#if!defined_COLUMN_H_#define_COLUMN_H_classColumn{doubleheight,radius;Column(doubler=2,doubleh=5);Column(Column&c);doublearea();doublevolume();voidset(doubler,double#include<iostream>#include"column.h"#definePI3.1415usingnamespaceColumn::Column(doubler,doubleh){radius=r;//注意缩进height=h}Column::Column(Column&c){radius=c.radius;//注意缩进height=c.heightdoublereturn}doublereturn}voidColumn::set(doublerdoubleh){radius=r;//注意缩进height=h}#include<iostream>#include"column.h"Columnone(1,1);usingnamespacestd;intmain(){doubleColumn*ptrColumnColumnthree(3,3);//注意缩进ptr=newColumn(4,4);//注意缩进staticColumnfive(5,5)注意缩进Columncout<<"Theareaofthecolumnis"<<t.area()<<endl;cout<<"Thevolumeofthecolumnis"<<t.volume()<<endl;ColumnT(t);cout<<"Theareaofthecolumnis"<<t.area()<<endl;//cout<<"Theheightandradiusis";cout<<"Theareaofthecolumnis"<<t.area()<<endl;cout<<"Thevolumeofthecolumnis"<<t.volume()<<endl;deleteptr;return}fourT局部对象在作用域结束时析构,作用域结束点相同时,先的对象后析构,后的对象delete#include<iostream>#include<cmath>usingnamespaceclassPoint{voidinputPoint(doublea,doubleb);//boolisEndPoint();doublegetX();doublegetY();doublex,voidPoint::inputPoint(doublea,double}boolreturnfalse;elsereturntrue}doublePoint::getX(){returnx;}doublePoint::getY(){returny;}classRectangle{voidboolisContainPoint(Pointp);doubleupperLeftX,upperLeftY;doublelowerRightX,lowerRightY;voidRectangle::inputRectangle(){doublex1,x2,y1,y2;}boolRectangle::isContainPoint(Pointreturntrue;elsereturnfalse;}int{Rectangler[10];Pointp;charinti=0,j=0;doublee,f;{}while(p.isEndPoint()){intfor(int{{cout<<"Point"<<j+1<<"iscontainedinfigure}}cout<<"Point"<<j+1<<"isnotcontainedinany}return}修订版本:Point类提供构造函数、set#include<iostream>#include<cmath>usingnamespacestd;classPoint{Point(doublea,doublevoidsetPoint(doublea,doubleb);boolisEndPoint();doublegetX();doubledoublex,Point::Point(doublea,doubleb){}voidPoint::setPoint(doublea,doubleb){}boolreturnfalse;}
returndoublePoint::getX(){returnx;}doublePoint::getY(){returny;}classRectangle{voidboolisContainPoint(Pointp);doubleupperLeftX,upperLeftY;doublelowerRightX,lowerRightY;voidRectangle::inputRectangle(){}boolRectangle::isContainPoint(Point}
returntrue;returnint{Rectangler[10];charR;inti=0,j=0;double{}Pointwhile{intfor(int{{cout<<"Point"<<j+1<<"iscontainedinfigure"<<k+1<<endl;}}cout<<"Point"<<j+1<<"isnotcontainedinany}return}usingnamespaceclasspoint{voidinputPoint();boolisEndPoint();doublegetX();doublegetY();doublex,voidpoint::inputPoint(){}boolif(fabs(x-9999.9)<1e-6&&fabs(y-9999.9)<1e-6)returnfalse;return}doublepoint::getX(){returnx;}doublepoint::getY(){returny;}classrectangle{voidboolisContainPoint(pointp);doubleupperLeftX,upperLeftY;doublelowerRightX,lowerRightY;voidrectangle::inputRectangle(){}boolrectangle::isContainPoint(pointp){doublex=p.getX();doubleif((x>upperLeftX&&x<lowerRightX)&&(y>lowerRightY&&y<upperLeftY))returntrue;return}int{intfCount=0;//图形个数intpCount=0;//点个数charfigure;//识别图形rectanglerec[10];//一个数组元素代表一个矩形while(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 肝移植术后免疫抑制方案
- 中国硼硅玻璃项目商业计划书
- 2025年中国食品甜味剂项目创业计划书
- 中国烟气脱硫项目创业计划书
- 2025年全球化的粮食安全问题与解决方案
- 2025年全球化的金融风险控制
- 2025年全球海洋酸化的生态影响
- 会计初级考试题型及答案
- 2025年中国透皮贴剂项目创业投资方案
- 中国丝绸专用洗涤剂项目投资计划书
- 《星际穿越》电影赏析
- 【经济环境对会计发展的影响5600字(论文)】
- 《电子制动系统》课件
- GB/T 43586-2023聚烯烃冷拉伸套管膜
- 安宁疗护心理护理课件
- 活出生命的意义课件
- 小学生心理健康教育主题班会和谐心灵 健康成长 课件
- 三查四定表完整版本
- (完整文本版)货物验收单
- 人教版九年级道德与法治 上册 第三单元《文明与家园》大单元整体教学设计
- pe样本树脂炭黑分散性能的研究
评论
0/150
提交评论