友元函数练习

#include <iostream.h>
#include <math.h>
class Point
{
private:
 double x,y;
public:
 void Setxy(double xx,double yy)
 {
  x=xx;y=yy;
 }
 friend double Distance(Point a,Point b)//计算距离
 {
  double l;
  l=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  return l;
 }
 friend void Comparation(Circle a,Point b);
};
class Circle
{
private:
 double x,y,r;
public:
 void Setxy(double xx,double yy,double rr)
 {
  x=xx;y=yy;r=rr;
 }
 friend void Comparation(Circle a,Point b)
 {
  double l;
  l=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
  if(l>=a.r)
   cout<<"out"<<endl;
  else if(l==a.r)
   cout<<"on"<<endl;
  else
   cout<<"in"<<endl;
 }
};
class Line
{
private:
 double x1,x2,y1,y2;
public:
 void Setxy(double xx1,double yy1,double xx2,double yy2)
 {
  x1=xx1;y1=yy1;
  x2=xx2;y2=yy2;
 }
 
};

class Rectangle
{
private:
 double x1,x2,x3,x4,y1,y2,y3,y4;
public:
 void Setxy(double xx1,double yy1,double xx2,double yy2,double xx3,double yy3,double xx4,double yy4)
 {
  x1=xx1;y1=yy1;
  x2=xx2;y2=yy2;
  x3=xx3;y3=yy3;
  x4=xx4;y4=yy4;
 }
};
void main()
{
 Point a,b;
 a.Setxy(2,3);
 b.Setxy(1,3);
}
 
 
 


 

posted on 2013-04-27 16:13  叛道者  阅读(151)  评论(0)    收藏  举报