Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cctype>
- #include <math.h>
- #include <string.h>
- using namespace std;
- struct Circle
- {
- int x, y, r;
- void init()
- {
- x = y = r = 0;
- }
- void input()
- {
- cout << "Input x y r: ";
- cin >> x >> y >> r;
- }
- char *toPChar()
- {
- char *str = new char[69];
- strcpy(str, "x = ");
- strcat(str, itos(x));
- strcat(str, "y = ");
- strcat(str, itos(y));
- strcat(str, "r = ");
- strcat(str, itos(r));
- return str;
- }
- char *itos(int n)
- {
- int len = 32;
- char *s = new char[len + 1];
- s[len] = '\0';
- for (int i = 1; i <= len; i++)
- {
- if (n != 0)
- {
- s[len - i] = n % 10 + 48;
- n /= 10;
- }
- }
- return s;
- }
- void output()
- {
- cout << toPChar() << endl;
- }
- };
- class TCircle
- {
- Circle c;
- public:
- void init()
- {
- c.init();
- }
- void input()
- {
- c.input();
- }
- char *toPChar()
- {
- return c.toPChar();
- }
- void output()
- {
- c.output();
- }
- float olen(int ang) //знаходження довжини дуги для заданого центрального кута;
- {
- return 3.14*c.r*ang / 180;
- }
- float spl(int ang) //обчислення площі сегмента для заданого центрального кута.
- {
- return c.r*c.r / 2 * (3.14*ang / 180 - sin(ang));
- }
- int isln(TCircle b) // визначення, чи покриває один круг другий;
- {
- if (sqrt(pow(b.c.x - c.x, 2) + pow(b.c.y, c.y)) < c.r + b.c.r) return 1;
- else return -1;
- }
- void setStruct(int x, int y, int r)
- {
- c.x = x;
- c.y = y;
- c.r = r;
- }
- Circle getStruct()
- {
- return c;
- }
- };
- float olen(Circle a, int ang) //знаходження довжини дуги для заданого центрального кута;
- {
- return 3.14*a.r*ang / 180;
- }
- float spl(Circle a, int ang) //обчислення площі сегмента для заданого центрального кута.
- {
- return a.r*a.r / 2 * (3.14*ang / 180 - sin(ang));
- }
- int isln(Circle a, Circle b) // визначення, чи покриває один круг другий;
- {
- if (sqrt(pow(b.x - a.x, 2) + pow(b.y, a.y)) < a.r + b.r) return 1;
- else return -1;
- }
- int main()
- {
- Circle a1, a2;
- TCircle b1, b2;
- a1.input();
- a2.input();
- a1.output();
- a2.output();
- cout << olen(a1, 20) << endl;
- cout << spl(a2, 30) << endl;
- cout << isln(a1, a2) << endl;
- b1.input();
- b2.input();
- b1.output();
- b2.output();
- cout << b1.olen(20) << endl;
- cout << b2.spl(30) << endl;
- cout << b1.isln(b2) << endl;
- cin.ignore();
- cin.get();
- }
Advertisement
Add Comment
Please, Sign In to add comment