Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.28 KB | None | 0 0
  1. // ТирГотовыйскомментамиитестом.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. // Test.cpp: определяет точку входа для консольного приложения.
  5. //
  6.  
  7. #include "stdafx.h"
  8. #include <iostream>
  9. #include <ctime>
  10. #include <cmath>
  11. #define LINE " __________________________________________________"
  12. #define LINE1 " -------------------------------------------------- "
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17.     float  *arrX, *arrY, *rad, kol_vis;
  18.     srand(time(NULL));
  19.     float X = 0;
  20.     float Y = 0;
  21.     int A;
  22.     int R, R2;
  23.  
  24.     cout << "Razmer misheni: " << endl;
  25.     cin >> A;
  26.     R = 4 * A;
  27.     R2 = R*R;
  28.     float pramaya = sqrt(R2);
  29.  
  30.     /*  int kol_tochek;
  31.     cout << "Kollichestvo vistrelov : " << endl;
  32.     cin >> kol_tochek;*/
  33.     const int n = 10;
  34.  
  35.     int i;
  36.     int flag = 0;
  37.     int k;
  38.     cout << "Vvedite kol-vo tochek iz kryga" << endl;
  39.     cin >> k;
  40.     float *arrayX = new float[k];
  41.     float *arrayY = new float[k];
  42.     float *arrayRad = new float[k];
  43.     int *arrayRez = new int[k];
  44.     int countX = 0;
  45.     int countY = 0;
  46.     int countRad = 0;
  47.     int countRez = 0;
  48.     do {
  49.  
  50.         X = (double)rand() / RAND_MAX * 2 * R - R;
  51.         Y = (double)rand() / RAND_MAX * 2 * R - R;
  52.         //X = (rand() % 100)/ (rand() % 3+1);
  53.         //  Y = (rand() % 100)/ (rand() % 3 + 1);
  54.         //X = (rand() % 3 + 1)*-1;
  55.         //Y = (rand() % 3 + 1)*-1;
  56.         if ((X*X + Y*Y <= R*R)) {
  57.             cout << X << " " << Y << endl;
  58.             //arrayX[1] = -3;
  59.             //arrayY[1] = -2;
  60.             arrayX[countX] = X;
  61.             countX++;
  62.             arrayY[countY] = Y;
  63.             countY++;
  64.             arrayRad[countRad] = sqrt(pow(X, 2) + pow(Y, 2));
  65.             countRad++;
  66.             //  break;
  67.             if ((X*X + Y*Y <= R*R) && (Y >= -X - pramaya))
  68.             {
  69.                 arrayRez[countRez] = 1;
  70.                 countRez++;
  71.                 cout << "Yes " << endl;
  72.             }
  73.             else
  74.             {
  75.                 arrayRez[countRez] = 0;
  76.                 countRez++;
  77.                 cout << "No " << endl;
  78.             }
  79.             flag++;
  80.         }
  81.  
  82.     } while (flag<k);
  83.  
  84.     cout << endl;
  85.  
  86.     for (int count = 0; count < k; count++)
  87.         //cout << arrayX[count] << " " << arrayY[count] << endl;
  88.         cout << arrayRez[count] << endl;
  89.  
  90.  
  91.     cout << "                 Tablitcya rezyltatov " << endl;
  92.     cout << " ___________________________________________________________" << endl;
  93.  
  94.     cout << "|" << "  Nomer  " << "|" << "     X     " << "|" << "     Y     " << "|" << "       R     " << "|" << " Rezultal  " << "|" << endl;
  95.     for (int count = 0; count < k; count++)
  96.     {
  97.  
  98.         if (arrayRez[count] == 1)
  99.         {
  100.             cout << " -----------------------------------------------------------";
  101.             printf("\n| %4d    | %6.2f    | %6.2f    |   %6.2f    |   Norma   |\n", count + 1, arrayX[count], arrayY[count], arrayRad[count]);
  102.             //  cout << "|    Norma     |";
  103.             //  printf("Hi %с %d %s", 'с', 10, "there!");
  104.             //  cout << count<<" " << arrayRad[count]<<" "<<arrayX[count] << " " << arrayY[count] << " Norma" << endl;
  105.         }
  106.         if (arrayRez[count] == 0)
  107.         {
  108.             cout << " -----------------------------------------------------------";
  109.             printf("\n| %4d    | %6.2f    | %6.2f    |   %6.2f    |   Brak    |\n", count + 1, arrayX[count], arrayY[count], arrayRad[count]);
  110.         }
  111.         //cout << count <<" " << arrayX[count] << " " << arrayY[count] << " Brak" << endl;
  112.  
  113.  
  114.     }
  115.     cout << " -----------------------------------------------------------" << endl;
  116.  
  117.     system("pause");
  118.     return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement