Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <ctime>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. const long double pi = 3.14159265;
  9.  
  10. struct Point
  11. {
  12.     int number;
  13.     float x;
  14.     float y;
  15.     double radius;
  16.     string status;
  17. };
  18.  
  19.  
  20. int main()
  21. {
  22.     float A;
  23.     int K;
  24.  
  25.     srand(time(0));
  26.  
  27.     cout << "Введите A, K" << endl;
  28.     cin >> A >> K;
  29.  
  30.     Point* array = new Point [K];
  31.  
  32.     int strike_count = 0;
  33.  
  34.     float max_r = 0, min_r = 4*A;
  35.     int minr_index = -1, maxr_index = -1;
  36.  
  37.     for (int i = 0; i < K; i++) {
  38.         array[i].number = i;
  39.        
  40.         do {
  41.             array[i].x =  (float)rand() / RAND_MAX * 8 * A - 4 * A;
  42.             array[i].y = (float)rand() / RAND_MAX * 8 * A - 4 * A;
  43.         } while (array[i].x*array[i].x + array[i].y*array[i].y >= 16*A*A);
  44.  
  45.         array[i].radius = sqrt(array[i].x*array[i].x+array[i].y*array[i].y);
  46.  
  47.         if (array[i].radius > max_r) {
  48.             maxr_index = i;
  49.             max_r = array[i].radius;
  50.         }
  51.         if (array[i].radius < min_r) {
  52.             minr_index = i;
  53.             min_r = array[i].radius;
  54.         }
  55.  
  56.         if (array[i].x*array[i].x+array[i].y*array[i].y <= 4*A*A) {
  57.             if (0.5*abs(array[i].x)+abs(array[i].y) > A) {
  58.                 array[i].status = "Норма";
  59.                 strike_count++;
  60.             }
  61.             else {
  62.                 array[i].status = "Брак";
  63.             }
  64.         }
  65.         else {
  66.             array[i].status = "Брак";
  67.         }
  68.     }
  69.  
  70.  
  71.     cout << "Таблица попавших" << endl << endl;
  72.     int counter = 0;
  73.     for (int i = 0; i < K; i++) {
  74.         if (array[i].status == "Норма") {
  75.             counter++;
  76.             cout << array[i].number + 1 << " " <<
  77.                 "(" << array[i].x << ", " << array[i].y << ")" << " " <<
  78.                 array[i].radius << " "
  79.                 << array[i].status << endl;
  80.         }
  81.     }
  82.     cout << "Процент точек: " << 100.0*counter/K << endl;
  83.     cout << endl;
  84.  
  85.  
  86.     cout << "Таблица не попавших" << endl << endl;
  87.     counter = 0;
  88.     for (int i = 0; i < K; i++) {
  89.         if (array[i].status == "Брак") {
  90.             counter++;
  91.             cout << array[i].number + 1 << " " <<
  92.                 "(" << array[i].x << ", " << array[i].y << ")" << " " <<
  93.                 sqrt(array[i].x*array[i].x+array[i].y*array[i].y) << " "
  94.                 << array[i].status << endl;
  95.         }
  96.     }
  97.     cout << "Процент точек: " << 100.0*counter/K << endl;
  98.     cout << endl << "Процент попадания точек в область: " << 100.0*strike_count/K << "%" << endl;
  99.     cout << "Отношение площади мишени к площади круга: " << (pi*4*A*A-4*A*A)/(16*A*A*pi) << endl;
  100.     cout << "Максимально удаленная точка: " << "(" << array[maxr_index].x << ", " << array[maxr_index].y << ")" << " " <<
  101.     "Расстояние: " << array[maxr_index].radius << endl;
  102.     cout << "Минимально удаленная точка: " << "(" << array[minr_index].x << ", " << array[minr_index].y << ")" << " " <<
  103.     "Расстояние: " << array[minr_index].radius << endl;
  104.  
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement