hozer

[OOP]VencLab3

Oct 14th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. #include <math.h>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8. struct Circle
  9. {
  10.     int x, y, r;
  11.  
  12.     void init()
  13.     {
  14.         x = y = r = 0;
  15.     }
  16.  
  17.     void input()
  18.     {
  19.         cout << "Input x y r: ";
  20.         cin >> x >> y >> r;
  21.     }
  22.  
  23.     char *toPChar()
  24.     {
  25.         char *str = new char[69];
  26.         strcpy(str, "x = ");
  27.         strcat(str, itos(x));
  28.         strcat(str, "y = ");
  29.         strcat(str, itos(y));
  30.         strcat(str, "r = ");
  31.         strcat(str, itos(r));
  32.         return str;
  33.     }
  34.  
  35.     char *itos(int n)
  36.     {
  37.         int len = 32;
  38.         char *s = new char[len + 1];
  39.         s[len] = '\0';
  40.         for (int i = 1; i <= len; i++)
  41.         {
  42.             if (n != 0)
  43.             {
  44.                 s[len - i] = n % 10 + 48;
  45.                 n /= 10;
  46.             }
  47.         }
  48.  
  49.         return s;
  50.     }
  51.  
  52.     void output()
  53.     {
  54.         cout << toPChar() << endl;
  55.     }
  56.  
  57. };
  58.  
  59. class TCircle
  60. {
  61.     Circle c;
  62.  
  63. public:
  64.     void init()
  65.     {
  66.         c.init();
  67.     }
  68.  
  69.     void input()
  70.     {
  71.         c.input();
  72.     }
  73.  
  74.     char *toPChar()
  75.     {
  76.         return c.toPChar();
  77.     }
  78.  
  79.     void output()
  80.     {
  81.         c.output();
  82.     }
  83.  
  84.     float olen(int ang) //знаходження довжини дуги для заданого центрального кута;
  85.     {
  86.         return 3.14*c.r*ang / 180;
  87.     }
  88.  
  89.     float spl(int ang) //обчислення площі сегмента для заданого центрального кута.
  90.     {
  91.         return c.r*c.r / 2 * (3.14*ang / 180 - sin(ang));
  92.     }
  93.  
  94.     int isln(TCircle b) // визначення, чи покриває один круг другий;
  95.     {
  96.         if (sqrt(pow(b.c.x - c.x, 2) + pow(b.c.y, c.y)) < c.r + b.c.r) return 1;
  97.         else return -1;
  98.     }
  99.  
  100.     void setStruct(int x, int y, int r)
  101.     {
  102.         c.x = x;
  103.         c.y = y;
  104.         c.r = r;
  105.     }
  106.  
  107.     Circle getStruct()
  108.     {
  109.         return c;
  110.     }
  111. };
  112.  
  113.  
  114. float olen(Circle a, int ang) //знаходження довжини дуги для заданого центрального кута;
  115. {
  116.     return 3.14*a.r*ang / 180;
  117. }
  118.  
  119. float spl(Circle a, int ang) //обчислення площі сегмента для заданого центрального кута.
  120. {
  121.     return a.r*a.r / 2 * (3.14*ang / 180 - sin(ang));
  122. }
  123.  
  124. int isln(Circle a, Circle b) // визначення, чи покриває один круг другий;
  125. {
  126.     if (sqrt(pow(b.x - a.x, 2) + pow(b.y, a.y)) < a.r + b.r) return 1;
  127.     else return -1;
  128. }
  129.  
  130. int main()
  131. {
  132.     Circle a1, a2;
  133.     TCircle b1, b2;
  134.    
  135.     a1.input();
  136.     a2.input();
  137.     a1.output();
  138.     a2.output();
  139.     cout << olen(a1, 20) << endl;
  140.     cout << spl(a2, 30) << endl;
  141.     cout << isln(a1, a2) << endl;
  142.  
  143.  
  144.     b1.input();
  145.     b2.input();
  146.     b1.output();
  147.     b2.output();
  148.     cout << b1.olen(20) << endl;
  149.     cout << b2.spl(30) << endl;
  150.     cout << b1.isln(b2) << endl;
  151.  
  152.     cin.ignore();
  153.     cin.get();
  154. }
Advertisement
Add Comment
Please, Sign In to add comment