Advertisement
AnyaAS

Ukazateli_4_2

Mar 3rd, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.29 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <iostream>
  4. #include <time.h>
  5. #include <stdlib.h>
  6. #include <conio.h>
  7. using namespace std;
  8.  
  9. void Init1(int *mas, int size1);
  10. void Init2(int *arr, int size2);
  11. void Print(int *mas, int size1, int *arr, int size2);
  12. void Funk(int *mas, int size1, int *arr, int size2);
  13.  
  14. int _tmain(int argc, _TCHAR* argv[])
  15. {
  16.     setlocale(LC_ALL, "Russian");
  17.     srand(time(NULL));
  18.     int size1 = rand() % 10 + 2;
  19.     int size2 = rand() % 10 + 2;
  20.     int *mas = new int[size1];
  21.     int *arr = new int[size2];
  22.     Init1(mas, size1);
  23.     Init2(arr, size2);
  24.     for (;;)
  25.     {
  26.         system("cls");
  27.         Print(mas, size1, arr, size2);
  28.         cout << "1. Сравнить массивы по содержанию" << endl;
  29.         cout << "2. Сравнить массивы по длине" << endl;
  30.         cout << "3. Обновить массивы" << endl;
  31.         cout << "4. Выход" << endl;
  32.         int v;
  33.         cin >> v;
  34.         switch (v)
  35.         {
  36.         case 1:
  37.             Funk(mas, size1, arr, size2);
  38.             _getch();
  39.             break;
  40.         case 2:
  41.             if (size1 == size2)
  42.             {
  43.                 cout << "Массивы равны" << endl;
  44.             }
  45.             else
  46.             {
  47.                 cout << "Массивы не равны" << endl;
  48.             }
  49.             _getch();
  50.             break;
  51.             case 3:
  52.                 size1 = rand() % 10 + 2;
  53.                 size2 = rand() % 10 + 2;
  54.                 Init1(mas, size1);
  55.                 Init2(arr, size2);
  56.                 break;
  57.             case 4:
  58.                 exit(0);
  59.             default: break;
  60.         }
  61.     }
  62.     delete[]mas;
  63.     delete[]arr;
  64. }
  65.  
  66. void Init1(int *mas, int size1)
  67. {
  68.     for (int i = 0; i < size1; i++)
  69.     {
  70.         mas[i] = rand() % 30;
  71.     }
  72. }
  73. void Init2(int *arr, int size2)
  74. {
  75.     for (int i = 0; i < size2; i++)
  76.     {
  77.         arr[i] = rand() % 30;
  78.     }
  79. }
  80. void Print(int *mas, int size1, int *arr, int size2)
  81. {
  82.     cout << "Массив №1" << endl;
  83.     for (int i = 0; i < size1; i++)
  84.     {
  85.         cout.width(4);
  86.         cout << mas[i];
  87.     }
  88.     cout << endl;
  89.     cout << "Массив №2" << endl;
  90.     for (int i = 0; i < size2; i++)
  91.     {
  92.         cout.width(4);
  93.         cout << arr[i];
  94.     }
  95.     cout << endl;
  96. }
  97. void Funk(int *mas, int size1, int *arr, int size2)
  98. {
  99.     int count = 0;
  100.     for (int i = 0; i < size1; i++)
  101.     {
  102.         for (int j = 0; j < size2; j++)
  103.         {
  104.             if (mas[i] == arr[j])
  105.             {
  106.                 count++;
  107.                 break;
  108.             }
  109.         }
  110.     }
  111.     if (count == size1 || count == size2)
  112.     {
  113.         cout << "Массивы равны" << endl;
  114.     }
  115.     else
  116.     {
  117.         cout << "Массивы не равны" << endl;
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement