Advertisement
Petro_zzz

lesson7_321

Jul 17th, 2023
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void is_divide3() {
  6.     int value = 0;
  7.     cout << "Введите целое число ";
  8.     cin >> value;
  9.  
  10.     if (value % 3 == 0) {
  11.         cout << value << " делится на 3";
  12.     }
  13.     else {
  14.         cout << value << " не делится на 3";
  15.     }
  16.     cout << endl;
  17. }
  18.  
  19. void sort_two() {
  20.     int a, b;
  21.     cin >> a;
  22.     cin >> b;
  23.  
  24.     if (a > b) {
  25.         cout << b << ", " << a << endl;
  26.     }
  27.     else {
  28.         cout << a << ", " << b << endl;
  29.     }
  30. }
  31.  
  32. void sort_two2() {
  33.     int a, b;
  34.     cin >> a;
  35.     cin >> b;
  36.  
  37.     if (a == b) {
  38.         cout << "Равны " << a << endl;
  39.     }
  40.     else {
  41.         if (a > b) {
  42.             cout << b << ", " << a << endl;
  43.         }
  44.         else {
  45.             cout << a << ", " << b << endl;
  46.         }
  47.     }
  48. }
  49.  
  50. void test_goto() {
  51.     cout << 1 << " ";
  52.     cout << 2 << " ";
  53.     goto label;
  54.     cout << 3 << " ";
  55.     label: cout << 4 << " ";
  56.     cout << 5 << " ";
  57.     cout << endl;
  58. }
  59.  
  60.  
  61. void test_cyclic_goto() {
  62. start:  sort_two2();
  63.     char ch;
  64. enter: cout << "Вы хотите повторить? (y/n)";
  65.     cin >> ch;
  66.  
  67.     if (ch == 'y') {
  68.         goto start;
  69.     }
  70.  
  71.     if (ch == 'n') {
  72.         return;   // эта конструкция заканчивает выполнение функции
  73.     }
  74.     else {
  75.         goto enter; // это безусловный переход
  76.     }  
  77. }
  78.  
  79. bool disj(bool a, bool b) {
  80.     return a || b;
  81. }
  82.  
  83. bool conj(bool a, bool b) {
  84.     return a && b;
  85. }
  86.  
  87. bool imply(bool a, bool b) {
  88.     return !a || b;
  89. }
  90.  
  91. bool xnor(bool a, bool b) {
  92.     return (a && b) || (!a && !b);
  93. }
  94.  
  95. bool test_eq(bool a, bool b, bool c) {
  96.     bool arg1 = imply(xnor(!a, !b), !c);
  97.     bool arg2 = xnor(disj(!a, b), c);
  98.     return imply(arg1, arg2);
  99. }
  100.  
  101. void test_logic() {
  102.     /*
  103.     bool a = 0, b = 0;
  104.     cout << a << " " << b << " | " << xnor(a, b) << endl;
  105.     a = 0, b = 1;
  106.     cout << a << " " << b << " | " << xnor(a, b) << endl;
  107.     a = 1, b = 0;
  108.     cout << a << " " << b << " | " << xnor(a, b) << endl;
  109.     a = 1, b = 1;
  110.     cout << a << " " << b << " | " << xnor(a, b) << endl;
  111.     */
  112.     bool a, b, c;
  113.     cout << "a b c | eq" << endl;
  114.     /*cout << a << " "
  115.         << b << " "
  116.         << c << " | "
  117.         << test_eq(a, b, c) << endl;*/
  118.     cout << "0, 0, 0 | " << test_eq(0, 0, 0) << endl;
  119.     cout << "0, 0, 1 | " << test_eq(0, 0, 1) << endl;
  120.     cout << "0, 1, 0 | " << test_eq(0, 1, 0) << endl;
  121.     cout << "0, 1, 1 | " << test_eq(0, 1, 1) << endl;
  122.     cout << "1, 0, 0 | " << test_eq(1, 0, 0) << endl;
  123.     cout << "1, 0, 1 | " << test_eq(1, 0, 1) << endl;
  124.     cout << "1, 1, 0 | " << test_eq(1, 1, 0) << endl;
  125.     cout << "1, 1, 1 | " << test_eq(1, 1, 1) << endl;
  126.  
  127. }
  128.  
  129. bool is_body(double x, double y) {
  130.     return (2.0 <= x) && (x <= 3.0)
  131.         && (0.0 <= y) && (y <= 1.5);
  132. }
  133.  
  134. void shooter() {
  135.     double x;
  136.     double y;
  137.     cout << "Прицельтесь (введите x и y)" << endl;
  138.     cin >> x >> y;
  139.    
  140.     bool body_x = (2.0 <= x) && (x <= 3.0);
  141.     bool body_y = (0.0 <= y) && (y <= 1.5);
  142.     bool head_x = (2.4 <= x) && (x <= 2.6);
  143.     bool head_y = (1.5 <= x) && (x <= 1.7);
  144.    
  145.     bool body = body_x && body_y;
  146.     bool head = head_x && head_y;
  147.    
  148.     if (body && head) {
  149.         cout << "Бинго!!!" << endl;
  150.     }
  151.     else {
  152.         cout << "Промах." << endl;
  153.     }
  154. }
  155.  
  156. int main() {
  157.     setlocale(LC_ALL, "ru");
  158.     //cout << "Hello lesson 7\n";
  159.     //test_logic();
  160.     //test_goto();
  161.     //is_divide3();
  162.     shooter();
  163.  
  164.      system("pause");
  165.     return 0;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement