第11周项目3—点类派生直线类
来源:互联网 发布:opt算法c语言代码 编辑:程序博客网 时间:2024/05/22 08:05
#include<iostream>#include<Cmath>using namespace std;class Point //定义坐标点类{public: Point():x(0),y(0) {}; Point(double x0, double y0):x(x0), y(y0) {}; double getx(); double gety(); void PrintPoint(); //输出点的信息protected: double x,y; //点的横坐标和纵坐标};double Point::gety(){ return y;}double Point::getx(){ return x;}void Point::PrintPoint(){ cout<<"Point: ("<<x<<","<<y<<")"; //输出点}class Line: public Point //利用坐标点类定义直线类, 其基类的数据成员表示直线的中点{public: Line(Point pts, Point pte); //构造函数,用初始化直线的两个端点及由基类数据成员描述的中点 double Length(); //计算并返回直线的长度 void PrintLine(); //输出直线的两个端点和直线长度private: class Point pts,pte; //直线的两个端点,从Point类继承的数据成员表示直线的中点};Line::Line(Point pts1, Point pte1):Point((pts1.getx()+pte1.getx())/2,(pts1.gety()+pte1.gety())/2){pts=pts1;pte=pte1;}double Line::Length(){ return sqrt((pts.getx()-pte.getx())*(pts.getx()-pte.getx())+(pts.gety()-pte.gety())*(pts.gety()-pte.gety()));}void Line::PrintLine(){ cout<<"1st Point:("<<pts.getx()<<","<<pts.gety()<<")"<<endl; cout<<"2st Point:("<<pte.getx()<<","<<pte.gety()<<")"<<endl; cout<<"The Length of Line: "<<Length()<<endl;}int main(){ Point ps(-2,5),pe(7,9); Line l(ps,pe); cout<<"About the Line: "<<endl; l.PrintLine(); //输出直线l的信息:两端点及长度 cout<<"The middle point of Line is: "; l.PrintPoint(); //输出直线l中点的信息 return 0;}
0 0
- 第11周 项目3 点类派生直线类
- 第11周 【项目3 - 点类派生直线类】
- 第11周项目3-点类派生直线类
- 第11周项目3-点类派生直线类
- 第11周 项目3 点类派生直线类
- 第11周项目3 点类派生直线类
- 第11周项目三-点类派生直线类
- 第11周 项目三-点类派生直线类
- 第11周项目4-点类派生直线类
- 第10-11周项目:点类派生直线类
- 第10周-项目3-点类派生直线类
- 第10周项目3点类派生直线类
- 第10周项目3-点类派生直线类
- 第11周项目3—点类派生直线类
- 大一第二学期第11周【项目3—点类派生直线类】
- 第11周-继承与派生-项目4-点类派生直线类
- C++第10/11周项目 继承与派生 【点类派生直线类 】(复习新版)
- C++第11周(春)项目3 - 点类派生直线类
- phpcms头部代码详细分析 转载收藏
- 13-++.--
- 4.1 三维变换
- Design Patterns - Visitor Pattern
- IOS 获得版本
- 第11周项目3—点类派生直线类
- WPF 绑定各种数据源之Datatable
- Android基于ffmpeg媒体库小视频录制功能
- 14-priority_typeconversion
- Android Studio设置logcat颜色
- 文章标题
- 15-compilation_process
- hdu 5226 Tom and matrix
- linux添加开机启动项、登陆启动项、定时启动项、关机执行项等的方法