全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
8-3 (1)c1=(5,4)c2=(2,10)c3=c1-c2=(3,-6)c4=c1+c2=(7,14)(2)class A!class B!class C!class B!class C!(3)B1:display()D1:display()8-4 (1) x=p.x;y=p.y;x = p.get_x() & y = p.get_y()*this(2) virtual*ptrptr = &d8-5 (1)#include using namespace std;class Pointprivate: float x, y;public: Point(float xx=0, float yy=0) x = xx; y = yy; Point operator + (Point p) return Point(x+p.x, y+p.y); Point operator - (Point p) return Point(x-p.x, y-p.y); float getx() return x; float gety() return y; ;int main(void) Point one(1, 2), two(3, 4), a, b; a = (one + two); couta.getx(),a.gety()endl; b = (one - two); coutb.getx(),b.gety()endl; system(pause); return 0;(2)#include using namespace std;class Allpublic: int Double(int x) coutINTendl; return x*2; long Double(long x) coutLONGendl; return x*2; float Double(float x) coutFLOATendl; return x*2; double Double(double x) coutDOUBLEendl; return x*2; ;int main(void) All one; int a=5; long b=25; float c=3.14; double d=3.1415926; coutone.Double(a)endl; coutone.Double(b)endl; coutone.Double(c)endl; coutone.Double(d)endl; system(pause); return 0;(3)#include using namespace std;class Pointprivate: float x, y, z;public: Point(float xx=0, float yy=0, float zz=0) x = xx; y = yy; z = zz; Point operator + (Point p) return Point(x+p.x, y+p.y, z+p.z); Point operator - (Point p) return Point(x-p.x, y-p.y, z-p.z); Point operator = (Point p) return Point(x=p.x, y=p.y, z=p.z); void tell() cout(x,y,z)endl; ;int main(void) Point one(1, 2, 3), two(4, 5, 6); Point a, b; a = (one + two); b = (one - two); a.tell(); b.tell(); system(pause); return 0;(4)#include using namespace std;class vehiclepublic: virtual void tell(void)=0;class car:public vehiclepublic: void tell() coutCARendl; ;class truck:public vehiclepublic: void tell() coutTRUCKendl; ;class boat:public vehiclepublic: void tell() coutBOATendl; ;int main(void) car one; truck two; boat three; one.tell(); two.tell(); three.tell(); system(pause); return 0;(5)#include using namespace std;#include #define PI 3.14159265class Shapepublic: virtual float GetArea()=0; virtual float GetPerim()=0;class Rectangle:public Shapeprivate: float a, b, c; /三边长 public: Rectangle(float aa, float bb, float cc) a = aa; b = bb; c = cc; float GetArea() /海伦公式 float p=(a+b+c)/2; return sqrt(p*(p-a)*(p-b)*(p-c); float GetPerim() return a+b+c; ;class Circle:public Shapeprivate: float r; /半径public : Circle(float rr) r = rr; float GetArea() return PI*r*r; float GetPerim() return 2*PI*r; ;int main(void) Rectangle one(3, 3, 4); Circle two(6
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 陕西事业单位2026年考试备考考点试题及答案解析
- 2025年锦州北镇市面向社会公开招聘社区专职工作人员35人备考题库带答案详解
- 2025年下半年中国-东盟博览会秘书处公开招聘5人备考考点题库及答案解析
- 2025江西抚州市临川区招聘城市社区工作者(专职网格员)106人备考题库及完整答案详解1套
- 寻乌县2025年公开招聘社区工作者备考题库【10人】及一套参考答案详解
- 2026中国农业发展银校园招聘备考题库含答案详解(典型题)
- 2025鄂尔多斯东胜区招聘100名社区工作者备考题库含答案详解(预热题)
- 2025山西忻州市原平市招聘社区专职工作人员50人备考题库完整参考答案详解
- 2025沈阳市苏家屯区面向社会公开招聘社区工作者28人备考题库及答案详解一套
- 2026泸州银行校园招聘90人备考题库含答案详解(预热题)
- 医患代运营合同范本
- 6.2 好玩的华容道 课件 2025-2026学年二年级上册数学北师大版
- 统计法规培训
- 工地项目部征迁协调汇报
- 2025年税务师《税收征管法规》备考题库及答案解析
- 华为IPD研发质量管理精髓
- 香水销售知识培训内容课件
- 生产建设项目水土保持设施验收技术规程(2025版)
- 洒水车作业规范及安全操作规程
- 高速公路收费系统施工组织设计方案
- 2025年酒店行业全球酒店管理与酒店服务创新研究报告
评论
0/150
提交评论