#include <iostream>
using namespace std;
#include "Point.hpp"
Point::Point()
{
}
Point::Point( int a, int b ):
x(a), y(b)
{
}
void Point::SetX( int a )
{
x= a;
}
void Point::SetY( int a )
{
y= a;
}
void Point::SetXY( int a, int b )
{
x= a, y= b;
}
int Point::GetX() const
{
return x;
}
int Point::GetY() const
{
return y;
}
void Point::Print() const
{
cout << "X 坐标为 " << x << endl;
cout << "y 坐标为 " << y << endl;
}
//下面这些包含在文件 Circle.cpp 中
#include <iostream>
#include <cmath>
#include "Circle.hpp"
#include "Point.hpp"
using namespace std;
Circle::Circle ()
{
}
Circle::Circle( int a )
{
radius= a;
}
Circle::Circle( int a, int b, int c )
{
radius= a;
centre.SetXY( b, c);
}
Circle::Circle( int a, Point b )
{
radius= a;
centre= b;
}
void Circle::SetCentre( int a, int b )
{
centre.SetXY( a, b );
}
void Circle::SetCentre( Point p )
{
centre= p;
}
void Circle::SetRadius( int a )
{
radius= a;
}
void Circle::Print() const
{
cout << "半径为 " << radius << endl;
centre.Print();
}
int Circle::GetRadius() const
{
return radius;
}
Point Circle::GetCentre() const
{
return centre;
}
void Circle::Relation ( Circle& t )
{
double dis= sqrt( (double)(t.GetCentre().GetX()- centre.GetX())* (t.GetCentre().GetX()- centre.GetX())+
(t.GetCentre().GetY()- centre.GetY())* (t.GetCentre().GetY()- centre.GetY()) );
double r1= radius+ t.GetRadius();
double r2= abs( radius- t.GetRadius() );
if( dis== r1 || r2== dis ) cout<< "这两个圆相切" << endl;
else if( dis> r1 ) cout << "两圆相离" << endl;
else if( dis< r2 ) cout << "两圆包含" << endl;
else cout << "两圆相交" << endl;
}
#ifndef CIRCLE_HPP
#define CIRCLE_HPP
#include "Point.hpp"
class Circle
{
private:
int radius;
Point centre;
public:
Circle();
Circle( int );
Circle( int, Point );
Circle( int, int, int );
void SetRadius( int );
void SetCentre( int, int );
void SetCentre( Point );
int GetRadius() const;
Point GetCentre() const;
void Print() const;
void Relation( Circle& );
};
#endif
#pragma once
class Point
{
private:
int x, y;
public:
Point();
Point( int, int );
void SetX( int ); // 设置 X 值
void SetY( int ); // 设置 Y 值
void SetXY( int, int ); // 同时设置 X Y 值
int GetX() const; // 获得 X 值
int GetY() const; // 获得 Y 值
void Print() const; // 打印点信息
};
#include <iostream>
using namespace std;
#include "Circle.hpp"
#include "Point.hpp"
int main()
{
Circle t1( 1, Point(3,4) ), t2( 4, Point(6,8) );
t1.Print();
t1.Relation(t2);
t1.SetCentre( Point(4,4) );
t1.Print();
t1.Relation(t2);
t1.SetRadius( 5 );
t1.Print();
t1.Relation(t2);
cout << t1.GetCentre ().GetX() << " " << t1.GetCentre().GetY() << endl;
cout << t1.GetRadius () << endl;
return 0;
}
posted on 2009-03-03 18:03
Darren 阅读(5132)
评论(0) 编辑 收藏 引用