Advertisement
leo11

Untitled

Jun 9th, 2021
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. template <typename T>
  2. T* my_realloc(T* src, size_t old_size, size_t new_size){
  3.     T* new_src = new T[new_size];
  4.  
  5.     for (int i = 0; i < old_size; i++)
  6.         new_src[i] = src[i];
  7.    
  8.     delete [] src;
  9.     src = new_src;
  10.     return src;
  11. }
  12.  
  13. // class Cat{
  14. // public:
  15. //     Cat(string _name, int _age) : name(_name), age(_age){}
  16. //     Cat() : name(""), age(0){}
  17. //     string name;
  18. //     int age;
  19.  
  20. // };
  21.  
  22. // template<typename Type>
  23. // class Array{
  24. //     Type *data;
  25. //     int size;
  26. //     int count;
  27.  
  28. // public:
  29. //     Array(){
  30. //         size = 10;
  31. //         count = 0;
  32. //         data = new Type[size];
  33. //     }
  34.  
  35. //     void push_back(Type& item){
  36. //         if (count == size){
  37. //             size += 10;
  38. //             data = my_realloc<Type>(data, count, size);
  39. //         }
  40. //         data[count] = item;
  41. //         ++count;
  42. //     }
  43.  
  44. //     void pop_back(){
  45. //         --count;
  46. //     }
  47.  
  48. //     Type get(size_t index){
  49. //         return data[index];
  50. //     }
  51.  
  52. //     int index(Type item){
  53. //         int ret = -1;
  54. //         for (int i = 0; i < count; i++)
  55. //             if (data[i] == item)
  56. //                 ret = i;
  57. //         return ret;
  58. //     }
  59.  
  60. // };
  61.  
  62. template<class TYPE>
  63. TYPE round(TYPE t,int prec)
  64. {
  65.     for(int i=0;i<prec;i++)
  66.         t*=10;
  67.     int n=(int)t;
  68.     if(t-n>=0.5)
  69.        n++;
  70.     t=n;
  71.     for(int i=0;i<prec;i++)
  72.         t/=10;
  73.     return t;
  74. }
  75.  
  76.  
  77. struct Point{
  78.     int x, y;
  79. };
  80.  
  81. class Circle{
  82.  
  83.     Point centre;
  84.     double radius;
  85. public:
  86.     Circle(int x, int y, double rad){
  87.         centre.x = x;
  88.         centre.y = y;
  89.         radius = rad;
  90.     }
  91.  
  92.     Circle(){
  93.         centre.x = 0;
  94.         centre.y = 0;
  95.         radius = 10;
  96.     }
  97.    
  98.     double calcDistance(Circle& cir){
  99.         int dx = abs(centre.x - cir.centre.x);
  100.         int dy = abs(centre.y - cir.centre.y);
  101.         double dist = std::sqrt(dx * dx + dy * dy);
  102.         return round(dist, 1);
  103.     }
  104. };
  105.  
  106. class Sector : public Circle
  107. {
  108.     int angle;
  109.  
  110. public:
  111.    
  112. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement