Advertisement
Guest User

Untitled

a guest
Apr 15th, 2022
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include <windows.h>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. #include <stdlib.h> /* srand, rand */
  9. #include <time.h> /* time */
  10.  
  11. using namespace std;
  12.  
  13. class ArrayUser
  14. {
  15. public:
  16. vector <int> a0;
  17. vector <int> a1;
  18. int szArr;
  19.  
  20. ArrayUser()
  21. {
  22. szArr= 0;
  23. while (szArr<1)
  24. {
  25. cout << "Размер массива = "; cin >> szArr;
  26. }
  27.  
  28. }
  29. /////////////////
  30. void InitArr()
  31. {
  32. int i=0; int d;
  33. srand (time(NULL));
  34.  
  35. while (i<szArr)
  36. {
  37. d= rand() % 77 - 31; // [-31;45]
  38. a0.push_back(d);
  39. i++;
  40. }
  41. }
  42. //////////////////
  43. void OutArrA0(bool f)
  44. {
  45. int i=0; int d;
  46.  
  47. (f) ? d= a0.size() : d= a1.size();
  48. while (i<d)
  49. {
  50. (f) ? cout << a0[i] : cout << a1[i];
  51. cout << '\t';
  52. i++;
  53. }
  54. }
  55. ////////////////
  56. void FuncUser()
  57. {
  58. int i= 0; int d;
  59. while (i<a0.size())
  60. {
  61. d= a0[i];
  62. if (d%2) a1.push_back(d);
  63. i++;
  64. }
  65. }
  66.  
  67. };
  68. int main(int argc, char **argv)
  69. {
  70. system("chcp 1251 > nul"); // Руссификация сообщений
  71. setlocale(LC_ALL, "Russian");
  72.  
  73. ArrayUser au; au.InitArr();
  74. au.OutArrA0(true);
  75. au.FuncUser();
  76. cout << endl;
  77. au.OutArrA0(false);
  78. cout << endl;
  79.  
  80. system("pause"); // system("pause > nul");
  81. return 0;
  82. }
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement