Advertisement
NecroBoy

Лаба номер 1

Feb 14th, 2021 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. // Variant 20.cpp: определяет точку входа для консольного приложения.
  2. // 1, 2, 4, 6, 8
  3. #include "StdAfx.h"
  4. #include <iostream>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8. struct Dot
  9.     {
  10.         double x;
  11.         double y;
  12.         double radius;
  13.         bool axis;
  14.         int number;
  15.     };
  16.  
  17.  
  18. int main()
  19. {
  20.     setlocale(LC_CTYPE, "rus");
  21.     // Переменные
  22.     int num = 10;
  23.     int radius = 0;
  24.     cout << "Введите кол-во точек: ";
  25.     cin >> num;
  26.  
  27.     Dot* st = new Dot[num];
  28.     for (int i = 0; i < num; i++)
  29.     {
  30.         cout << "Введите x координату точки: ";
  31.         cin >> st[i].x;
  32.         cout << "Введите y координату точки: ";
  33.         cin >> st[i].y;
  34.         st[i].number = i+1;
  35.         st[i].radius = sqrt((st[i].x)*(st[i].x)+(st[i].y)*(st[i].y));
  36.         if (st[i].x == 0 || st[i].y == 0) {
  37.             st[i].axis = true;
  38.         }
  39.     }
  40.  
  41.     for (int i = 0; i < num; i++)
  42.     {
  43.         bool was_swapped = true;
  44.         while (was_swapped) {
  45.             was_swapped = false;
  46.             for (int i = 0; i < num - 1; i++) {
  47.                 if (st[i].radius > st[i+1].radius) {
  48.                     swap(st[i], st[i + 1]);
  49.                     was_swapped = true;
  50.  
  51.                 }
  52.             }
  53.  
  54.         }
  55.     }
  56.  
  57.     cout << "================================" << endl;
  58.  
  59.     for (int i = 0; i < num; i++)
  60.     {
  61.     cout << "Точка номер " << st[i].number << endl;
  62.     cout << "x: " << st[i].x << endl;
  63.     cout << "y: " << st[i].y << endl;
  64.     cout << "radius: " << st[i].radius << endl;
  65.  
  66.     if (st[i].axis == true) {
  67.         cout << "Точка лежит на координатной оси " << endl;
  68.     }
  69.     else {
  70.         cout << "Точка не лежит на координатной оси " << endl;
  71.     }
  72.  
  73.     cout << "================================" << endl;
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement