Advertisement
leo11

Untitled

Jun 9th, 2021
592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. template<class TYPE>
  2. TYPE round(TYPE t,int prec)
  3. {
  4.     for(int i=0;i<prec;i++)
  5.         t*=10;
  6.     int n=(int)t;
  7.     if(t-n>=0.5)
  8.        n++;
  9.     t=n;
  10.     for(int i=0;i<prec;i++)
  11.         t/=10;
  12.     return t;
  13. }
  14.  
  15.  
  16. struct Point{
  17.     int x, y;
  18. };
  19.  
  20. class Circle{
  21.  
  22.     Point centre;
  23.     double radius;
  24. public:
  25.     Circle(int x, int y, double rad){
  26.         centre.x = x;
  27.         centre.y = y;
  28.         radius = rad;
  29.     }
  30.  
  31.     Circle(){
  32.         centre.x = 0;
  33.         centre.y = 0;
  34.         radius = 10;
  35.     }
  36.    
  37.     double calcDistance(Circle& cir){
  38.         int dx = abs(centre.x - cir.centre.x);
  39.         int dy = abs(centre.y - cir.centre.y);
  40.         double dist = std::sqrt(dx * dx + dy * dy);
  41.         return round(dist, 1);
  42.     }
  43. };
  44.  
  45. class Sector : public Circle
  46. {
  47.     int angle;
  48.  
  49. public:
  50.     Sector() : Circle(){
  51.         angle = 0;
  52.     }
  53.    
  54.     Sector(int x, int y, double rad, int an) : Circle(x, y, rad){
  55.         angle = an;
  56.     }
  57. };
  58.  
  59.  
  60.  
  61. int main(){
  62.  
  63.     Circle x(10, 10, 20), xx(20, 20, 20);
  64.  
  65.     cout << x.calcDistance(xx) << endl;
  66.  
  67.     Sector z(10, 10, 20, 30), zz(20, 20, 20, 30);
  68.  
  69.     cout << z.calcDistance(zz) << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement