Advertisement
Nexeon

Untitled

Oct 13th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. float lenght(float x, float y) {
  5.     return sqrtf((x * x) + (y * y));
  6. }
  7.  
  8. int main() {
  9.  
  10.     setlocale(LC_ALL, "RUS");
  11.  
  12.     FILE *file;
  13.  
  14.     fopen_s(file, "1.dat", "r"); // Открываем файл
  15.  
  16.     char buff[100]; // Буфер
  17.  
  18.     float points[2][100]; // Массив точек!
  19.  
  20.     int i = 0; // Счетчик
  21.  
  22.     float x, y;
  23.  
  24.     while(fgets(buff, 100, file)) {
  25.        
  26.         sscanf_s(buff, "%f %f", &x, &y);
  27.  
  28.         points[0][i] = x;
  29.         points[1][i] = y;
  30.  
  31.         i++;
  32.     }
  33.  
  34.     // Определяем область принадлежности:
  35.  
  36.     int n;
  37.  
  38.     float radius = 2.f;
  39.  
  40.     for (int j = 0; j < i; j++) {
  41.         x = points[0][j];
  42.         y = points[0][j];
  43.  
  44.         if (y >= 0) {
  45.             if (y <= 1.f && (x >= -1.f || x <= 1.f)) {
  46.                 n = 3;
  47.             } else {
  48.                 if (lenght(x, y) <= radius) {
  49.                     n = 4;
  50.                 } else {
  51.                     n = 1;
  52.                 }
  53.             }
  54.         } else {
  55.             if (y >= -1.f && (x >= -1.f || x <= 1.f)) {
  56.                 n = 3;
  57.             } else {
  58.                 if (lenght(x, y) <= radius) {
  59.                     n = 4;
  60.                 } else {
  61.                     n = 2;
  62.                 }
  63.             }
  64.         }
  65.  
  66.         std::cout << "Точка " << j + 1 << ": (" << x <<
  67.         ";" << y << ") в зоне " << n << std::endl;
  68.     }
  69.  
  70.     fclose(file);
  71.  
  72.     system("pause");
  73.  
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement