Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- float lenght(float x, float y) {
- return sqrtf((x * x) + (y * y));
- }
- int main() {
- setlocale(LC_ALL, "RUS");
- FILE *file;
- fopen_s(file, "1.dat", "r"); // Открываем файл
- char buff[100]; // Буфер
- float points[2][100]; // Массив точек!
- int i = 0; // Счетчик
- float x, y;
- while(fgets(buff, 100, file)) {
- sscanf_s(buff, "%f %f", &x, &y);
- points[0][i] = x;
- points[1][i] = y;
- i++;
- }
- // Определяем область принадлежности:
- int n;
- float radius = 2.f;
- for (int j = 0; j < i; j++) {
- x = points[0][j];
- y = points[0][j];
- if (y >= 0) {
- if (y <= 1.f && (x >= -1.f || x <= 1.f)) {
- n = 3;
- } else {
- if (lenght(x, y) <= radius) {
- n = 4;
- } else {
- n = 1;
- }
- }
- } else {
- if (y >= -1.f && (x >= -1.f || x <= 1.f)) {
- n = 3;
- } else {
- if (lenght(x, y) <= radius) {
- n = 4;
- } else {
- n = 2;
- }
- }
- }
- std::cout << "Точка " << j + 1 << ": (" << x <<
- ";" << y << ") в зоне " << n << std::endl;
- }
- fclose(file);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement