码迷,mamicode.com
首页 > 编程语言 > 详细

C++学习(5)

时间:2018-06-29 19:19:07      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:turn   com   str   void   int   iostream   img   c++   IV   

 1 //设计一个线段类
 2 #include<iostream.h>
 3 class Point{
 4     private:
 5         int x;
 6         int y;
 7     public:
 8         Point(){}
 9         Point(int x,int y){
10             this->x=x;
11             this->y=y;
12         }
13         
14         Point(Point &c){
15             x=c.x;
16             y=c.y;
17         }
18 
19         ~Point(){
20         }
21         
22         int GetX() const{
23             return this->x;
24         }
25 
26         int GetY() const{
27             return this->y;
28         }
29 };
30 
31 
32 class Line{
33     private:
34         Point a;
35         Point b;
36     public:
37         Line(){}
38         Line(Point &a,Point &b){
39             this->a=a;
40             this->b=b;
41         }
42         ~Line(){
43         }
44 
45         void ShowA()const{
46             cout<<"a point is:"<<a.GetX()<<","<<a.GetY()<<endl;
47         }
48         void ShowB(){
49             cout<<"b point is:"<<b.GetX()<<","<<b.GetY()<<endl;
50         }
51 
52 };
53 
54 int main(){
55     Point a(1,1),b(2,2);
56     Line myLine(a,b);
57     myLine.ShowA();
58     myLine.ShowB();
59     return 0;
60 }

 

技术分享图片

C++学习(5)

标签:turn   com   str   void   int   iostream   img   c++   IV   

原文地址:https://www.cnblogs.com/Tobi/p/9244892.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!