| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 337 人关注过本帖
标题:逛一圈....c++教室,好地方.....
取消只看楼主 加入收藏
lianjiecuowu
Rank: 3Rank: 3
来 自:安徽
等 级:论坛游侠
帖 子:152
专家分:107
注 册:2011-5-20
结帖率:85.71%
收藏
 问题点数:0 回复次数:1 
逛一圈....c++教室,好地方.....
#include<iostream>
#include<cmath>
using namespace std;
class Point
{
      public:
      Point(void){cout<<"调用构造函数"<<endl;};
      Point(int a,int b);
      Point(int a,int b,int d);
      Point(Point &p);
      Point(Point& p1,Point& p2);
      void move(int a,int b);
      double distance(Point p1,Point p2);
      void countj(Point p1,Point p2);
      int display1(){return c;}
      private:
      int x;
      int y;
      int z;
      int c;                      //两点之间的距离用c表示
};
Point:: Point(int a,int b)
{
    x=a;
    y=b;
    cout<<"点的坐标为:("<<x<<","<<y<<")"<<endl;
}
Point:: Point(int a,int b,int d)
{
    x=a;y=b;z=d;
    cout<<"点的坐标为:("<<x<<","<<y<<","<<z<<")"<<endl;
}
Point:: Point(Point& p1,Point& p2)                    //借用两个按引用调用的参数的构造函数求两个点的法向量
{
    Point p3;
    p3.x=p1.y*p2.z-p1.z*p2.y;
    p3.y=p1.z*p2.x-p1.x*p2.z;
    p3.z=p1.x*p2.y-p1.y*p2.x;
    cout<<"两坐标的法向量为;("<<p3.x<<","<<p3.y<<","<<p3.z<<")"<<endl;
}
Point:: Point(Point &p)
{
   x=p.x;
   y=p.y;
   cout<<"点的坐标为:("<<x<<","<<y<<")"<<endl;
}
void Point::move(int a,int b)
{
    x=a;
    y=b;
    cout<<"点的位置移动到了:("<<x<<","<<y<<")"<<endl;
}
double Point::distance(  Point p1,Point p2)                   //定义的求数量级函数
{
     
       int dx;
       int dy;
       double distance;
       dx=p1.x-p2.x;
       dy=p1.y-p2.y;
       distance=sqrt(pow(dx,2)+pow(dy,2));
       return distance;      
}
void Point::countj(Point p1,Point p2)
{
    c=p1.x*p2.x+p1.y*p2.y;
}

int main()
{
    Point t1(2,3);
    Point t2(t1);
    t1.move(6,6);
    cout<<endl<<endl;
    Point t3;
    cout<<"两点之间的距离为:"<<t3.distance(t1,t2)<<endl;
    cout<<endl<<endl;
    Point t4;
    t4.countj(t1,t2);
    cout<<"两点之间的距离为:"<<t4.display1()<<endl;
    cout<<endl<<endl;
    Point t5(2,4,6);
    Point t6(5,6,2);
    Point t7(t5,t6);
   
    system("pause");
    return 0;
   
}
搜索更多相关主题的帖子: private return 好地方 
2011-06-09 22:57
lianjiecuowu
Rank: 3Rank: 3
来 自:安徽
等 级:论坛游侠
帖 子:152
专家分:107
注 册:2011-5-20
收藏
得分:0 
额...我定义的是按引用调用,不一定是要定义具体的对象,要取址符&就可以喽,不过还是要谢谢啊,那个类型转换,我感觉好像不一定要显式的写出来,定义的是double型的啊函数,不过还是写出来的好啊。直观,谢谢啊

Sharp your mind!
2011-06-10 08:05
快速回复:逛一圈....c++教室,好地方.....
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032010 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved