Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<class TYPE>
- TYPE round(TYPE t,int prec)
- {
- for(int i=0;i<prec;i++)
- t*=10;
- int n=(int)t;
- if(t-n>=0.5)
- n++;
- t=n;
- for(int i=0;i<prec;i++)
- t/=10;
- return t;
- }
- struct Point{
- int x, y;
- };
- class Circle{
- Point centre;
- double radius;
- public:
- Circle(int x, int y, double rad){
- centre.x = x;
- centre.y = y;
- radius = rad;
- }
- Circle(){
- centre.x = 0;
- centre.y = 0;
- radius = 10;
- }
- double calcDistance(Circle& cir){
- int dx = abs(centre.x - cir.centre.x);
- int dy = abs(centre.y - cir.centre.y);
- double dist = std::sqrt(dx * dx + dy * dy);
- return round(dist, 1);
- }
- };
- class Sector : public Circle
- {
- int angle;
- public:
- Sector() : Circle(){
- angle = 0;
- }
- Sector(int x, int y, double rad, int an) : Circle(x, y, rad){
- angle = an;
- }
- };
- int main(){
- Circle x(10, 10, 20), xx(20, 20, 20);
- cout << x.calcDistance(xx) << endl;
- Sector z(10, 10, 20, 30), zz(20, 20, 20, 30);
- cout << z.calcDistance(zz) << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement